加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – Xcode 7 UI测试:解除推送和位置警报

发布时间:2020-12-15 01:51:24 所属栏目:百科 来源:网络整理
导读:我遇到了Xcode 7 UI测试的问题。 我的用户登录后,应用程序会显示两个警报,即请求位置警报和推送通知警报。这些通知一个接一个地显示。位置一出现在第一位。 我尝试自动解除它们以开始我的测试。 为此,我添加了两个UIInterruptionMonitor,第一个用于Locat
我遇到了Xcode 7 UI测试的问题。

我的用户登录后,应用程序会显示两个警报,即请求位置警报和推送通知警报。这些通知一个接一个地显示。位置一出现在第一位。

我尝试自动解除它们以开始我的测试。

为此,我添加了两个UIInterruptionMonitor,第一个用于Location Alert,第二个用于Notification Push Alert。

addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
        /* Dismiss Location Dialog */
        if alert.collectionViews.buttons["Allow"].exists {
            alert.collectionViews.buttons["Allow"].tap()
            return true
        }
        return false
    }
    addUIInterruptionMonitorWithDescription("Push Dialog") { (alert) -> Bool in
        /* Dismiss Push Dialog */
        if alert.collectionViews.buttons["OK"].exists {
            alert.collectionViews.buttons["OK"].tap()
            return true
        }
        return false
    }

但是只触发了Location 1,从不调用Push Notifications UIInterruptionMonitor的处理程序。

如果我在请求位置UIInterruptionMonitor中返回true,则为this other post accepted answer指定。两个处理程序都被调用,但两个UIInterruptionMonitor中的alert参数都链接到请求位置警报视图,因此永远找不到“确定”按钮。

如何解除这两个连续的警报视图?

解决方法

虽然不理想,但我发现如果您只是等到一个授权对话框完成后再在应用程序中显示另一个授权对话框,则UI测试可以连续获取多个请求。

if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse || CLLocationManager.authorizationStatus() == .AuthorizedAlways {
        self.locationManager.requestLocation()
    } else {
        self.contactStore.requestAccessForEntityType(.Contacts) { _ in
            self.locationManager.requestWhenInUseAuthorization()
        }
    }

我实际上是在我的代码中请求访问不同位置的联系人,但它可以处理多个同时请求。

然后在我的测试中:

addUIInterruptionMonitorWithDescription("Location Dialog") { (alert) -> Bool in
        let button = alert.buttons["Allow"]
        if button.exists {
            button.tap()
            return true
        }
        return false
    }
    addUIInterruptionMonitorWithDescription("Contacts Dialog") { (alert) -> Bool in
        let button = alert.buttons["OK"]
        if button.exists {
            button.tap()
            return true
        }
        return false
    }

    app.buttons["Location"].tap()

    app.tap() // need to interact with the app for the handler to fire
    app.tap() // need to interact with the app for the handler to fire

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读