Skip to content

Instantly share code, notes, and snippets.

@thecb4
Created January 2, 2019 21:11
Show Gist options
  • Save thecb4/42f36fa1d1198a3d9899fc301b6949d1 to your computer and use it in GitHub Desktop.
Save thecb4/42f36fa1d1198a3d9899fc301b6949d1 to your computer and use it in GitHub Desktop.
Extend XCUIApplication with UserBehavior protocol
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