ios - UIAutomation 和 XCTestCase : how to wait for a button to activate

标签 ios ios-ui-automation xctest xcode7 xcode-ui-testing

我正在编写一个 UIAutomation 测试用例,我需要等待用户被激活才能继续。似乎没有很好的方法来检查按钮是否更改为启用状态。

最好的方法是等待 UI 中发生某些事情,然后再检查它的状态?

dispatch_after 和 NSTimer 似乎都不起作用。他们只是阻止然后失败。

最佳答案

如果您使用 NSPredicates 和期望值,这实际上非常容易。您甚至可以设置超时值。此示例向您展示如何使用 5 秒超时执行此操作。

let exists = NSPredicate(format:"enabled == true")
expectationForPredicate(exists, evaluatedWithObject: app.tables.textFields["MY_FIELD_NAME"], handler: nil)
waitForExpectationsWithTimeout(5, handler: nil)

关于ios - UIAutomation 和 XCTestCase : how to wait for a button to activate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31300372/

相关文章:

ios - 嵌入式 Facebook 帖子在 UIWebView 中无法正确显示

ios - 格式化 NSTimeInterval

ios - 无法将实时数据库代码转换为 Firestore 代码

ios - 如何更新 parse.com 中的数据浏览器 channel ?

iphone - iOS UIAutomation UIAActivityIndi​​cator

ios - iPhone app UI自动化测试设计

iphone - 如何改进 iPhone UI 自动化?

swift - 有什么方法可以得到 XCTAssertTrue() 的结果吗?

ios - XCTest Swift - 如何更快或更精确地滑动?

swift - 在单元测试中捕获调试窗口输出?