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)
}
}
A small clarification - to get the pop-up so that it appears in the middle of the screen, disable cell data only for the Safari app. Otherwise the pop-up is shown at the top of the screen and doesn't interfere with the tap on Safari.