【发布时间】:2017-01-02 12:32:24
【问题描述】:
我正在为 Xcode UI 测试应用程序使用 swift。我们的被测应用程序有时会弹出一个“Alert Box”,影响测试用例的正常工作流程。无法预测弹出窗口何时出现。它可能出现在测试用例 1 或测试用例编号 x 处。
我想关闭“警报框”并继续测试用例的其余部分。如何在不影响测试用例正常流程的情况下,使用 swift XCUITest 框架处理类似 ASYNC 性质的事件?
到目前为止我已经找到了:
expectationForPredicate(exists, evaluatedWithObject: alertbox, handler: nil)
waitForExpectationsWithTimeout(300, handler: nil)
由于两个原因,这是不可行的。
- 无法预测超时
-
正在阻塞测试用例流
func testTestCase1 { let expectation = expectationWithDescription("Alert Found! Dismissing") do { // ... // test steps // ... expectation.fulfill() } waitForExpectationsWithTimeout(300) { dimissAlert() } }
参考1:
https://www.bignerdranch.com/blog/asynchronous-testing-with-xcode-6/
参考2:
XCTest and asynchronous testing in Xcode 6
参考3:https://adoptioncurve.net/archives/2015/10/testing-asynchronous-code-in-swift/
是否有一种通用的方法来处理整个套件中的异步事件?如何在另一个线程等待“警报框”出现事件时继续测试?
干杯!
【问题讨论】:
标签: swift xcode macos asynchronous xcode-ui-testing