我正在为我的项目编写UI测试用例。
我的项目流程如下:
因此,当我全新安装应用程序时,此流程将记录在测试用例中,如果我执行新的构建,则可以正常工作。
但问题是,当我在旧版本上进行测试时,没有针对位置许可的警报,并且测试失败。每次运行测试时,我如何处理这种情况或询问用户是否允许?
为了重置用户的凭据,我将launchArguments传递给XCUIApplication()
并在AppDelegate中处理。
我已经实现了代码,如果它的正确方法让我知道:
addUIInterruptionMonitor(withDescription: "Allow “APP” to access your location?") { (alert) -> Bool in
alert.buttons["Only While Using the App"].tap()
return true
}
如果警报到来,上述代码适用于两者。
使用中断监视器是正确的方法。但是,在与警报交互之前,检查显示的警报是否是您期望的警报更安全:
addUIInterruptionMonitor(withDescription: "Allow “APP” to access your location?") { (alert) -> Bool in
let button = alert.buttons["Only While Using the App"]
if button.exists {
button.tap()
return true // The alert was handled
}
return false // The alert was not handled
}