ios - 如何在 Xcode 的 UITests 下等待,直到某些 View 可见以供点击?

标签 ios swift xcode-ui-testing

有时,在 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()

关于ios - 如何在 Xcode 的 UITests 下等待,直到某些 View 可见以供点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39788690/

相关文章:

iphone - 如何在 iPhone 中制作无限 ScrollView ?

swift - 替换 readerSession 中的 CoreNFC UI?

swift - XCUITest 应用程序快捷方式

objective-c - NSPredicate 匹配

ios - 根据矩形请求设置属性。 iOS, swift

ios - Firebase 邀请与 Facebook 登录一起使用

ios - 可以在 iOS 中读取 protected NFC 标签吗?

ios - 如何向 iPhone 发送低心率通知?

ios - 使用 pod 中的测试代码在物理设备上运行 Xcode ui 测试

使用 Realm 进行 Swift XCTest UI 测试