在某一点上调用了许多web服务调用。我只想等30秒,因为我知道这段时间一切都会结束。我需要第一个粗略的解决方案。
我试过这个,但它引起了一些错误:
tablesQuery.buttons["Button"].tap()
DispatchQueue.main.asyncAfter(deadline: .now() + 30.0) {
let tablesQuery2 = tablesQuery
你知道吗?
最简单的方法是暂时停止执行:
sleep(30)
然而,如果你期望某个东西出现,最好使用内置的等待存在的功能:
element.waitForExistence(30)
如果什么都没有出现,它不会失败,所以如果它是你逻辑的关键部分,你可能最好通过计时器的预期来检查它:
let exists = NSPredicate(format: "exists == %@", true)
expectationForPredicate(exists, evaluatedWithObject: element, handler: nil)
waitForExpectationsWithTimeout(30, handler: nil)