如何在 Xcode 中的 UITests 下等待,直到某些视图可见以供点击?
How to wait under UITests in Xcode until some view will be visible for tap?
有时在 Xcode 中的 UITests 下,编译器会在按钮加载和显示之前尝试点击按钮。然后出现no matched found for...
.
这样的问题
但对此的简单解决方案是:
sleep(1) //wait 1 second and give `mybutton` time to load and be accessible for uitests
mybutton.tap()
但这太可怕了,因为我不能把 0.1
作为参数放在那里。在很多按钮之前等待 1 秒让我很烦。
有没有办法等到它对uitests可见?
您应该创建一个 XCTestExpectation 并等待它完成
expectationForPredicate(NSPredicate(format: "hittable == true"), evaluatedWithObject: mybutton, handler: nil)
waitForExpectationsWithTimeout(10.0, handler: nil)
mybutton.tap()
有时在 Xcode 中的 UITests 下,编译器会在按钮加载和显示之前尝试点击按钮。然后出现no matched found for...
.
但对此的简单解决方案是:
sleep(1) //wait 1 second and give `mybutton` time to load and be accessible for uitests
mybutton.tap()
但这太可怕了,因为我不能把 0.1
作为参数放在那里。在很多按钮之前等待 1 秒让我很烦。
有没有办法等到它对uitests可见?
您应该创建一个 XCTestExpectation 并等待它完成
expectationForPredicate(NSPredicate(format: "hittable == true"), evaluatedWithObject: mybutton, handler: nil)
waitForExpectationsWithTimeout(10.0, handler: nil)
mybutton.tap()