Handling system sheet-style alert in UITest

I'm trying to write a UITest to verify the following: the user taps a button in the app. The app then initiates a phone call by calling UIApplication's openURL method with a tel://*** url.

In the simulator, the openURL attempt fails and then the completionHandler is called with the success parameter set to false. In my app, I then display a UIAlertController, which I can then look for in my UI Test.

On device, openURL works and the system prompts the user to dial the number, by system UI that looks like a sheet. Is there any way for my UITest to see that sheet so that I can verify its contents? The phone number can vary based on the user's locale so I want to test that the correct phone is displayed per region.

Replies

The modal that appears with the "Call (123) 456-7890" "button" and Cancel button belongs to the Springboard app. So if you attach to com.apple.springboard in your XCUITest you can check for a *label* with the "Call ..." text. For some reason that is actually a label/staticText and not a button.

Code Block
    func testCalling() throws {
        // launch our app
        let app = XCUIApplication()
        app.launch()
// trigger the app's call to OpenUrl
        app.buttons["Call"].tap()
        let springBoard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
        print(springBoard.staticTexts.allElementsBoundByAccessibilityElement)
    }