Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handler of addUIInterruptionMonitor is not called for Alert related to Photos

Tags:

private func acceptPermissionAlert() {      _ = addUIInterruptionMonitor(withDescription: "") { alert -> Bool in          if alert.buttons["Don’t Allow"].exists { //doesnt get here second time              alert.buttons.element(boundBy: 1).tapWhenExists()              return true         }          return false     } } 

and this doesnt work for:

enter image description here

In the beginning of the app, it works perfect while acepting permission for notifications, but here... doesnt work.

Do you know why?

like image 289
Bartłomiej Semańczyk Avatar asked Oct 11 '16 09:10

Bartłomiej Semańczyk


1 Answers

I'vs found that addUIInterruptionMonitor sometimes doesn't handle an alert in time, or until tests have finished. If it isn't working, try using Springboard, which manages the iOS home screen. You can access alerts, buttons, and more from there, and this is particularly useful for tests where you know exactly when an alert will show.

So, something like this:

`let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")   let alertAllowButton = springboard.buttons.element(boundBy: 1) if alertAllowButton.waitForExistence(timeout: 5) {    alertAllowButton.tap() }` 

The buttons.element(boundBy:1) will ensure you tap the button on the right, change 1 to 0 to tap the left, (because sometimes the ' in "Don't Allow" causes a problem).

like image 190
Taylor Lindsay Avatar answered Sep 21 '22 16:09

Taylor Lindsay