关闭位置服务请求对话框
Posted
技术标签:
【中文标题】关闭位置服务请求对话框【英文标题】:dismiss location services request dialog 【发布时间】:2017-09-18 09:57:35 【问题描述】:在我的 UI 测试开始时,我有
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
它应该,但它什么也不做,它永远不会到达处理程序。我也尝试在setUp()
中设置此代码,但它也不起作用。
我认为问题可能是应用程序中发生的第一件事是显示对话框,可能为时过早(可能在调用addUIInterruptionMonitor
之前发生)
我该如何解决这个问题?
【问题讨论】:
【参考方案1】:您必须在添加 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"]
来关闭对话框。
【讨论】:
以上是关于关闭位置服务请求对话框的主要内容,如果未能解决你的问题,请参考以下文章
如何从 PhoneGap iOS 6 应用程序中删除位置服务请求?