Search code examples
iosxcodexcode-ui-testingxctestcase

How to access Apple Id "Sign In" dialog from UI Test?


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:

enter image description here

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"?


Solution

  • 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()