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


Code Block swift
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.

Same for me 2 months later.

You might be able to grab the alert you need directly from the springboard?

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

let allowBtn = springboard.buttons["Allow"]
if allowBtn.waitForExistence(timeout: 10) {
allowBtn.tap()
}
Yeah, that's what i have to use but it causes the tests to become flakey.

This was working before but no longer is strangely enough.
does not work for me either after update to xcode 12
Cant seem to grab it from the springboard (nice idea though). Any other suggestions?
I hit the same issue with xcode 12 + iOS 12.4.1, xcode 12 + iOS 13.6. The automation testing is blocked.
I hit the same issue with xcode 12.2 + iOS 12.4.1, xcode 12.2 + iOS 13.6. The notification is not captured. There is no problem if it is built via xcode 11.7, and run with iOS 12.4.1. The code is:
Code Block
let token = addUIInterruptionMonitor(withDescription: "Notification") { (alert) -> Bool in
let allow = alert.buttons["Allow"]
if allow.exists {
allow.tap()
return true
}
return false
}
// Interruption won't happen without some kind of action.
app.tap()
removeUIInterruptionMonitor(token)


While It works for iOS 13.7/iOS 14.3 + xcode 12.2

We recently upgraded xcode from 11 to 12. It worked before upgrading.

Resolution:
Add following code after above code(above code is still needed for iOS 13.7):
Code Block
app.tap()
let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let allowBtn = springboard.buttons["Allow"]
if allowBtn.waitForExistence(timeout: 2) {
allowBtn.tap()
}

It works for iOS 12.4.1. Please be aware that app.tap() is required to make the app active although we eyes see it. If app.tap() does not work, you could use other code to interact with the app so that the app becomes active, e.g. tap Settings button.

When debugging, please notice the following log should appear. It means the notification is captured. If it does not appear, continue trying to use other code to interact with the app so that the app becomes active, e.g. tap Settings button, until the log appears.
t = 12.30s Wait for com.apple.springboard to idle
t = 12.44s Requesting snapshot of accessibility hierarchy for app with pid 55
t = 12.54s Find: Descendants matching predicate identifier == "NotificationShortLookView" OR elementType == 7



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