【问题标题】:dismiss location services request dialog关闭位置服务请求对话框
【发布时间】:2023-03-28 10:46:01
【问题描述】:

在我的 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 之前发生)

我该如何解决这个问题?

【问题讨论】:

    标签: ios swift xcode-ui-testing


    【解决方案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"] 来关闭对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2016-09-24
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      • 2017-02-16
      • 2010-12-13
      相关资源
      最近更新 更多