2

I need to run continuous integration on xcode server using a lot of simulators. Is there a way to force it to always accept permission alerts like:

Allow "App" to access your photos

and so on...

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • Possible duplicate of http://stackoverflow.com/questions/32148965/xcode-7-ui-testing-how-to-dismiss-a-series-of-system-alerts-in-code ? – Aaron Sofaer Sep 30 '16 at 19:02

1 Answers1

8

In your setUp() method, create an interruption monitor and handle the alert by tapping the OK button. This means that whenever you try to interact with the app, a check will be made to see if the permissions view is in the way, and tap the OK button.

let permissionInterruptionMonitor = addUIInterruptionMonitor(withDescription: "Photos permission alert") { (alert) in
    alert.buttons["OK"].tap()
    return true // The interruption has been handled
}

If there are other alerts that may appear in your app with an OK button, but you don't want those to be automatically handled, you should make sure that the interruption monitor handler checks that it is the alert that you want to handle.

let permissionInterruptionMonitor = addUIInterruptionMonitor(withDescription: "Photos permission alert") { (alert) in
    if alert.staticTexts["\"AppName\" Would Like To Access Your Photos"].exists {
        alert.buttons["OK"].tap()
        return true // The interruption has been handled
    }
    return false // The interruption has not been handled
}
Oletha
  • 7,324
  • 1
  • 26
  • 46
  • How do you know which description text to use? I'm trying with location and notification permissions and I'm not able to catch them... thanks! – Jesuslg123 Aug 16 '17 at 13:28
  • 1
    @Jesuslg123 You just need to look at the notification when it comes up and see what the buttons say, it may differ between OS versions and locales. :( – Oletha Aug 16 '17 at 13:30
  • @Oletha Ok, make senses :P So no way to explore with identifiers in order to solve localized alerts isn't it? – Jesuslg123 Aug 16 '17 at 13:40
  • That's right. Alert views don't support accessibility identifiers for some reason. – Oletha Aug 16 '17 at 13:54