How to close the system alert in iOS10 simulator, Xcode 9, UITests

425 views Asked by At

I have the issue that I could not close the notification, location, photo access permission alert in iOS10 simulator, Xcode 9, UITests, but it works well in iOS11 simulator.

I found the thread that discuss about the similar issue, but there is not any useful workaround to fix it.

https://forums.developer.apple.com/thread/86989

1

There are 1 answers

0
ergunkocak On

Did you try

app.tap()

in the place you expect the dialog?

Or this method : https://useyourloaf.com/blog/handling-system-alerts-in-ui-tests/

This worked for me in setup method after app.launch()

     addUIInterruptionMonitor(withDescription: "System Dialog") { (alert) -> Bool in
        let savePasswordButton = alert.buttons["Save Password"]
        if savePasswordButton.waitForExistence(timeout: 3) {
            savePasswordButton.tap()
            return true
        }
        let allowButton = alert.buttons["Allow"]
        if allowButton.waitForExistence(timeout: 3) {
            allowButton.tap()
            return true
        }
        self.app.tap()
        return false
    }