XCTest / Xcode 9 beta 5: Unable to tap "Allow" on System Alert

Originator:nagarkarchetan
Number:rdar://33842609 Date Originated:08/10/2017
Status:Open Resolved:No
Product:Xcode Product Version:9.0 beta 5
Classification:Error Reproducible:Always
 
Summary:
I am using XCode 9 beta 5 to setup a XCTest. For my app, the app pops up a system alert for Notifications when the app is opened first time after installation.
Before Xcode 9, if i tried to tap button on the screen present, XCTest would tap 'Don't Allow' button by default and proceed.

Now, I am trying to tap 'Allow' using this code:

XCUIApplication().alerts["“AppName” Would Like to Send You Notifications"].buttons["Allow"].tap()

The above line was generated by UI Recorder and does not work in the test. It fails with this error:
 
Assertion Failure: xyz.swift:38: No matches found for Find: Descendants matching type Alert from input {(
    Application, 0x174186f50, pid: 3772, label: 'AppName'
)}

I have referred this StackOverflow answer until now, and the UIInterruption Monitor did not work in Xcode 9, or I could not get it working fully.
https://stackoverflow.com/a/32228033/2181419

Read this:
https://developer.apple.com/documentation/xctest/xctestcase/1496273-adduiinterruptionmonitor#parameters

but could not write a functioning handler in Swift.

What I tried until now:
        addUIInterruptionMonitor(withDescription: "Notifications Dialog") { (alert) -> Bool in
                alert.buttons["Allow"].tap()
                return true
        }

            app.buttons["Allow"].tap()
            app.tap()

Any help is appreciated, even if I can dismiss the notifications alert by tapping "Don't Allow" instead of "Allow"

Steps to Reproduce:
1. Install an app that requires Push Notification permissions
2. Write an XCTest which tries to tap "Allow" on the Notifications system alert view
3. Record tapping "Allow" using UIRecorder
4. Run the above test in Xcode

Expected Results:
System Alert for Notifications is dismissed by tapping 'Allow' and rest of the test continues.

Observed Results:
Test fails with error similar to:
No matches found for Find: Descendants matching type Alert from input {(
    Application, 0x174186f50, pid: 3772, label: 'AppName'
)}

Version:
XCode Version 9.0 beta 5 (9M202q)
macOS 10.12.6 (16G29)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!