Created
January 2, 2019 21:11
-
-
Save thecb4/42f36fa1d1198a3d9899fc301b6949d1 to your computer and use it in GitHub Desktop.
Extend XCUIApplication with UserBehavior protocol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension XCUIApplication: UserBehavior { | |
static var user: UserBehavior { | |
return XCUIApplication() | |
} | |
func wait(_ timeout: TimeInterval, for states: [ApplicationState]) { | |
let state = XCTWaiter.wait(for: states, timeout: timeout) | |
switch state { | |
case .completed: | |
XCTAssert(true, "waiting succeeded") | |
return | |
default: | |
XCTAssert(false, "waiting failed") | |
return | |
} | |
} | |
func login() { | |
self.buttons["Login"].tap() | |
} | |
func swipeToShowSearch() { | |
let tablesQuery = self.tables | |
let scrollElement1 = tablesQuery.staticTexts["New Releases"] | |
let scrollElement2 = tablesQuery.staticTexts["Coming Soon"] | |
scrollElement1.press(forDuration: 2, thenDragTo: scrollElement2) | |
} | |
func search(for text: String) { | |
self.searchFields["Such sights to show you..."].tap() | |
self.searchFields["Such sights to show you..."].typeText(text) | |
} | |
func select(_ text: String) { | |
let predicate = NSPredicate(format: "label CONTAINS[c] %@", text) | |
let row = self.tables.staticTexts.containing(predicate).firstMatch | |
row.tap() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment