在Xcode UI测试中等待30秒

时间:2018-11-05 19:15:19

标签: ios xcode-ui-testing

此时将调用许多Web服务。我只想等待30秒,因为我知道所有操作都将在这段时间内完成。我需要一个初步的解决方案。

我尝试过此方法,但是会引起一些错误:

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

你有什么主意吗?

1 个答案:

答案 0 :(得分:1)

最简单的方法是暂时暂停执行:

sleep(30)

但是,如果您希望某些东西出现,最好使用the build in function来等待存在:

element.waitForExistence(30)

如果什么都没有出现,它不会失败,因此,如果这是您逻辑的关键部分,则最好通过计时器的期望值进行检查:

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