Par*_*oja 2 xcode ui-testing ios xctest xcode-ui-testing
我正在为我的项目编写 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
}
Run Code Online (Sandbox Code Playgroud)
无论警报是否出现,上面的代码都适用于两者。
使用中断监视器是正确的方法。但是,在与警报交互之前检查显示的警报是否是您期望的警报会更安全:
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |