我正在使用斯威夫特的Xcode UI测试应用程序。我们被测试的应用程序有时会弹出一个“警报盒”,它会影响测试用例的正常工作流程。无法预测弹出窗口何时会出现。它可能出现在测试用例1或测试用例编号x。
我想放弃“警报箱”,继续测试用例的其余部分。如何在不影响测试用例正常流的情况下,用快速XCUITest框架处理类似ASYNC性质的事件?
到目前为止,我发现:
expectationForPredicate(exists, evaluatedWithObject: alertbox, handler: nil)
waitForExpectationsWithTimeout(300, handler: nil)
这是不可行的,因为有两个原因。
Ref1:https://www.bignerdranch.com/blog/asynchronous-testing-with-xcode-6/
Ref2:XCTest and asynchronous testing in Xcode 6
Ref3:https://adoptioncurve.net/archives/2015/10/testing-asynchronous-code-in-swift/
是否有一种通用的方法来处理跨套件的异步事件?如何在另一个线程等待“警报盒”出现事件时继续进行测试?
干杯!
发布于 2016-08-30 05:57:23
Stephen是对的,UI中断监视器应该工作得很好。我建议将其添加到测试设置中,以便为所有测试运行。
class UITests: XCTestCase {
let app = XCUIApplication()
override func setUp() {
super.setUp()
addUIInterruptionMonitorWithDescription("Alert") { (alert) -> Bool in
alert.buttons["OK"].tap()
return true
}
app.launch()
}
func testFoo() {
// example test
}
}
发布于 2016-08-25 17:43:49
Xcode 7.1添加了addUIInterruptionMonitorWithDescription,这似乎是您要寻找的。这里的文档:https://developer.apple.com/reference/xctest/xctestcase/1496273-adduiinterruptionmonitorwithdesc?language=objc
https://stackoverflow.com/questions/39156066
复制相似问题