Swift2 UI Test - Wait for Element to Appear

前端 未结 6 1227
逝去的感伤
逝去的感伤 2021-02-13 15:40

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

6条回答
  •  萌比男神i
    2021-02-13 16:29

    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()
    

提交回复
热议问题