I want to have a test pause and wait for an element to appear on screen before proceeding.
I don\'t see a good way to create an expectation for this and wait using
Based on onmyway133 code I came up with to extensions (Swift 3.2):
extension XCTestCase {
func wait(for element: XCUIElement, timeout: TimeInterval) {
let p = NSPredicate(format: "exists == true")
let e = expectation(for: p, evaluatedWith: element, handler: nil)
wait(for: [e], timeout: timeout)
}
}
extension XCUIApplication {
func getElement(withIdentifier identifier: String) -> XCUIElement {
return otherElements[identifier]
}
}
So on your call site you can use:
wait(for: app.getElement(withIdentifier: "ViewController"), timeout: 10)