简体   繁体   中英

Dismissing location and notifcation settings Xcode Ui testing

I am writing UI tests for my app. 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. I only want the alert OK to be dismissed when it pops up not on the first thing for launch.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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