Ios 取消位置服务请求对话框
在我的UI测试开始时,我有Ios 取消位置服务请求对话框,ios,swift,xcode-ui-testing,Ios,Swift,Xcode Ui Testing,在我的UI测试开始时,我有 addUIInterruptionMonitor(withDescription: "Location Dialog") { (alert) -> Bool in let button = alert.buttons["Allow"] if button.exists { snapshot("request location service") button.tap() return true
addUIInterruptionMonitor(withDescription: "Location Dialog") { (alert) -> Bool in
let button = alert.buttons["Allow"]
if button.exists {
snapshot("request location service")
button.tap()
return true
}
return false
}
它应该关闭location services request对话框,但它什么也不做,也永远不会到达处理程序。我还尝试在setUp()
中设置此代码,但也没有成功
我认为问题可能在于应用程序中发生的第一件事是显示对话框,这可能太早了(可能发生在调用addUIInterruptionMonitor
之前)
如何解决此问题?添加UIInterruptionMonitor后,您必须立即与应用程序交互。这可以是一个简单的点击:
addUIInterruptionMonitor(withDescription: "Location Dialog") { (alert) -> Bool in
let button = alert.buttons["Allow"]
if button.exists {
button.tap()
return true
}
return false
}
// interact with the app
app.tap()
如果app.tap()
干扰您的测试,您也可以使用app.swipeUp()
请注意,位置服务权限对话框已在iOS11中更改。现在有3个按钮,因此您必须使用alert.Buttons[“Always Allow”]
关闭对话框