I have some UI tests and wanna test what happens when I press "subscribe" button. In simulator there is an alert displayed asking to sign in with apple id:
I tried to wait for alert using app.alerts["Sign In"]
predicate and using addUIInterruptionMonitor
function. No luck. I even tried to wait for "Cancel" button to appear, this also didn't work.
Any ideas how to handle this alert and press "Cancel"?
The problem with this alert is that it is not being created from your app, but from the system app - Springboard. So, to be able to query elements from that app, you have to create XCUIApplication
object with the Springboard bundle ID:
let springboardApp = XCUIApplication(bundleIdentifier: "com.apple.springboard")
Then, find your alert with:
let signInAlert = springboardApp.alerts.element
You should then be able to find the Cancel button:
signInAlert.buttons["Cancel"].tap()