For my test automation project I use addUIInterruptionMonitor to keep the tests running smoothly. On iOS 17 this function seems to never get triggered. This code snippet contains a test that passes on iOS 15 and 16, but not on iOS 17 (tested on iPhone 12, iOS 15.5, iPhone 13 Mini, iOS 16.4.1 and iPhone 14 Pro, iOS 17.0).
To run the test, disable wifi and cell data on the test device first.
import XCTest
class Interruptions: XCTestCase {
func testCatchInterruption() {
// Run test on device with wifi and cell data disabled
var caughtInterruption = false
addUIInterruptionMonitor(withDescription: "Generic Alert Handler") { element -> Bool in
element.buttons["OK"].tap()
caughtInterruption = true
return true
}
let safariApp = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
safariApp.launch()
// Expect to see pop-up saying "Cellular Data is turned off"
safariApp.tap()
sleep(5)
// Pop-up should be gone
XCTAssert(caughtInterruption)
}
}
Update:
It seems like this IS a bug in iOS 17. Alerts generated by SpringBoard do not get automatically handled by the XCTest interruption handler. However, Alerts generated by your application are still handled properly.
There is a workaround, which is to manually call into SpringBoard and tap a button to close the Alert. This workaround would need to be executed outside the context of an interruption handler.
Here is a code example that does that:
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
springboard.buttons["Close"].tap()
Apologies for this. We are investigating a longer-term fix.