Skip to content

Instantly share code, notes, and snippets.

@pilot34
Last active April 24, 2018 10:44
Show Gist options
  • Save pilot34/1ad965ea6e05dd40d282453051c13a34 to your computer and use it in GitHub Desktop.
Save pilot34/1ad965ea6e05dd40d282453051c13a34 to your computer and use it in GitHub Desktop.
func wait(forWebViewElement element: XCUIElementTypeQueryProvider, timeout: TimeInterval = 20) {
// xcode has bug, so we cannot directly access webViews XCUIElements
// as a workaround we can check debugDesciption and parse it, that works
let predicate = NSPredicate { obj, _ in
guard let el = obj as? XCUIElement else {
return false
}
// If element has firstMatch, than there will be description of that at the end
// If no match - it will be ended with "FirstMatch\n"
return !el.firstMatch.debugDescription.hasSuffix("First Match\n")
}
// we need to take .firstMatch, because we parse description for that
let e = XCTNSPredicateExpectation(predicate: predicate, object: element.firstMatch)
let result = XCTWaiter().wait(for: [ e ], timeout: timeout)
XCTAssert(result == .completed)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment