简体   繁体   English

取消位置和通知设置Xcode Ui测试

[英]Dismissing location and notifcation settings Xcode Ui testing

I am writing UI tests for my app. 我正在为我的应用编写UI测试。 I have two alerts, location and notifications. 我有两个警报,位置和通知。 I am struggling to find a solution in order to dismiss these alerts. 我正在努力寻找解决方案以消除这些警报。

Currently I am using 目前我正在使用

systemAlertMonitorToken = addUIInterruptionMonitorWithDescription(systemAlertHandlerDescription) { (alert) -> Bool in
    if alert.buttons.matchingIdentifier("OK").count > 0 {
         alert.buttons["OK"].tap()
         return true
     } else {
         return false
     }
}

and

let notifications = self.app.alerts.element.collectionViews.buttons["OK"]
if notifications.exists {
    notifications.tap()
}

however both functions are not allowing me to dismiss the alerts. 但是,这两个功能均不允许我关闭警报。

EDIT 编辑

Now I have added 现在我添加了

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

to my code, but it means my tests are failing due to the XCT looking for the button "OK" straight away when it isnt a notification what pops up straight away. 到我的代码,但这意味着我的测试失败了,因为XCT在没有通知立即弹出的情况下立即寻找“确定”按钮。 I only want the alert OK to be dismissed when it pops up not on the first thing for launch. 我只希望警报OK弹出时(而不是要启动的第一件事)被关闭。

The interruption monitor will only trigger the next time you try to interact with the app, so you need to have code after the interruption monitor is registered to do whatever you want to do after dismissing the alert, eg tapping another button in your UI. 中断监视器只会在您下次尝试与应用程序进行交互时触发,因此在注册中断监视器后,您需要输入代码,以在解除警报后执行您想做的任何事情,例如,在UI中点击另一个按钮。

When the code gets to the part where you next interact with the UI, the handler for the completion handler will be executed and the system alert will be dealt with. 当代码到达您接下来与UI进行交互的部分时,将执行完成处理程序的处理程序,并处理系统警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM