XCUItest addUIInterruptionMonitor is not capturing alerts on iOS14 simulator and xcode 12

1.1k views Asked by At
override func setUp() {
    addUIInterruptionMonitor(withDescription: "App store alert") { (alert) -> Bool in
        alert.buttons.element(boundBy: 0).tap()
        return true
         }
}


func test() {
    functionThatCausesAlertToAppear()
    XCUIApplication().tap()
}

When I attempt to print a statement within the addUIInterruptionMonitor it doesn't print leading me to believe that the block isn't triggered.

2

There are 2 answers

1
Dimi On

Although this does not solve the issue at hand I've found a workaround from: addUIInterruptionMonitor(withDescription:handler:) not working on iOS 10 or 9

let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") 

let allowBtn = springboard.buttons["Allow"]
if allowBtn.waitForExistence(timeout: 10) {
    allowBtn.tap()
}
0
Deepak Badiger On

If you are running into the issue where your interruption is not firing even after making sure the code is correct, then read this documentation on Apple website - Handling UI Interruptions.

I too faced this challenge, and after realizing the issue, i simply identified the OK button and tapped on it in the flow.

Hope this helps in your case too!