Search code examples
iosxcode-ui-testing

Wait 30 sec in Xcode UI Test


At a point many web service call is get called. and I just want to wait 30sec, as I know all will finish during this time period. I need a first rough solution.

I tried this, but it raise some error:

tablesQuery.buttons["Button"].tap()
        DispatchQueue.main.asyncAfter(deadline: .now() + 30.0) {
            let tablesQuery2 = tablesQuery

Do you have any idea?


Solution

  • The simplest way is just sleeping the execution for the time being:

    sleep(30)
    

    However, in case you are expecting something to appear, it's better to use the built-in function for waiting for existence:

    element.waitForExistence(30)
    

    It doesn't fail if nothing appears, so if it's crucial part of your logic, you probably better to check it via expectation with timer:

    let exists = NSPredicate(format: "exists == %@", true)
    expectationForPredicate(exists, evaluatedWithObject: element, handler: nil)
    waitForExpectationsWithTimeout(30, handler: nil)