I want to automate tests for my iOS app and start writing UITests. Sometimes system alerts appear, and my tests have to simulate button tapping. In iOS and iPadOS these alerts are available via the system Springboard application:
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let cancelButton = springboard.alerts.buttons["Cancel"].firstMatch
if cancelButton.exists {
cancelButton.tap() // <-- cancel button taps, and test continue working
}
But when I launch my test in the Vision Pro simulator, the springboard is not available:
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
print(springboard.exists) // <-- "false" will be printed, springboard does not exist
It means that I can't automate button tapping in system alerts.
So, my question is:
How can I access system alerts in VisionOS and tap buttons by UITests?
I was googling my question and found addUIInterruptionMonitor method:
app.launch()
addUIInterruptionMonitor(withDescription: "System Dialog") { (alert) -> Bool in
alert.buttons["Allow"].tap()
return true
}
app.tap()
We only have to enter an appropriate description and the necessary button title.