Search code examples
iosswiftxcode-ui-testing

Call button on UI Testing?


I was wondering if it's possible to tap call button from tel's scheme (e.g tel//555555555). Because if I touch call button I'll have an alert that I need to confirm my call or cancel it. Is it possible?

I have this on my code:

addUIInterruptionMonitor(withDescription: "Phone Dialog") { (alert) -> Bool in
        let button = alert.buttons["Llamar"]
        if button.exists {
            button.tap()
            return true
        }
        return false
    }
    app.tap()
    XCTAssert(app.buttons["call_button"].exists, "No se encuentra el boton de llamar")
    app.buttons["call_button"].tap()
    sleep(2)

Any Idea? Regards


Solution

  • The UIInteractionMonitor does not work in the case of the phone call system dialog. The phone call dialog is handled by the Springboard and not your app.

    Xcode 9 allows you access to the Springboard so you can tap on the "Call" button by doing this:

    func testPhoneCall() {
        let app = XCUIApplication()
        let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
    
        app.launch()
        app.buttons["call_button"].tap()
    
        // tap on the call button
        springboard.buttons["Llamar"].tap()
    
    }