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
This question was asked about Swift2 but it's still a top search result in 2019 so I wanted to give an up-to-date answer.
With Xcode 9.0+ things are a bit simpler thanks to waitForExistence:
let app = XCUIApplication()
let myButton = app.buttons["My Button"]
XCTAssertTrue(myButton.waitForExistence(timeout: 10))
sleep(1)
myButton.tap()
WebViews Example:
let app = XCUIApplication()
let webViewsQuery = app.webViews
let myButton = webViewsQuery.staticTexts["My Button"]
XCTAssertTrue(myButton.waitForExistence(timeout: 10))
sleep(1)
myButton.tap()