ios - 在 Xcode UI 测试中等待 30 秒

标签 ios xcode-ui-testing

在某一时刻,许多网络服务调用被调用。我只想等 30 秒,因为我知道所有的事情都会在这段时间内完成。我需要第一个粗略的解决方案。

我试过了,但它引发了一些错误:

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

你有什么想法吗?

最佳答案

最简单的方法就是暂时休眠执行:

sleep(30)

但是,如果您希望出现某些内容,最好使用 the built-in function等待存在:

element.waitForExistence(30)

如果什么都没有出现,它不会失败,所以如果它是你逻辑的关键部分,你可能最好通过带有计时器的期望来检查它:

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

关于ios - 在 Xcode UI 测试中等待 30 秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53160745/

相关文章:

ios - 使用 firefox 插件创建的 .sqlite 文件如何打开

iphone - iOS UIScrollview 自动布局 - UILayoutFittingCompressedSize

xcode-ui-testing - 如何使用 Xcode UI 测试断言屏幕上无法命中被遮挡的 XCUIElement

xcode7 - 如何通过 Xcode 7 中的 UI 测试运行 iOS 应用程序中的代码?

ios - UITapGestureRecognizer 操作不起作用

ios - NSUserDefaults 还是后端?

ios - 链接器错误 - 尝试链接到 arm,但链接器使用 x86

macos - 使用 Xcode : How to find a button that has no title? 进行 UI 测试

ios - 使用并行测试一次运行所有测试时,输入文本字段不稳定

ios - 使用 Cocoapods 的 Xcode 7 UI 测试在设备上失败