In my UI tests I'm using the addUIInterruptionMonitorWithDescription
method as pointed in various places (1, 2, 3), as below:
var systemAlertMonitorToken: NSObjectProtocol?
override func setUp() {
super.setUp()
SDStatusBarManager.sharedInstance().enableOverrides()
continueAfterFailure = false
let app = XCUIApplication()
setupSnapshot(app)
app.launchEnvironment["UITests"] = "true"
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
XCUIDevice.sharedDevice().orientation = .LandscapeLeft
} else {
XCUIDevice.sharedDevice().orientation = .Portrait
}
app.launch()
systemAlertMonitorToken = addUIInterruptionMonitorWithDescription("Photos Permission Alert") { (alert) -> Bool in
if alert.buttons.matchingIdentifier("OK").count > 0 {
alert.buttons["OK"].tap()
// Required to return focus to app
app.tap()
return true
} else {
return false
}
}
}
override func tearDown() {
if let systemAlertMonitorToken = systemAlertMonitorToken {
removeUIInterruptionMonitor(systemAlertMonitorToken)
}
super.tearDown()
}
func testSomethingWithPhotos() {
let app = XCUIApplication()
// This will trigger the photos permission alert
app.tabBars.buttons["Scan"].tap()
// ... further tests
}
This functions are expected (the ""App Name" Would Like to Access Your Photos" alert is dismissed) on iPhones, but when run on an iPad, the alert is displayed but it is not dismissed, and if I place a breakpoint in the callback it is never triggered. Is there a way to have this function on iPads?
I have also tried:
- Placing the app.tap()
call in the testSomethingWithPhotos
function after the app.tabBars.buttons["Scan"].tap()
line, but no luck.
- Putting the call to addUIInterruptionMonitorWithDescription
before the super.setup()
call.
- Putting the call to addUIInterruptionMonitorWithDescription
in the testSomethingWithPhotos
function, before the line that would trigger the alert