Trying to automate allowing push notifications in UI test and UI interruption monitor does not trigger

255 Views Asked by At

I am trying to write a UI test for my iOS Swift app in order to automate screenshots with Fastlane. My app requests push notification permissions in its AppDelegate's didFinishLaunchingWithOptions, so when the application is first launched on a new device (which is going to be the case since I will erase the simulator between each running of my UI test), I want the permissions to be allowed before I can interact with the rest of the app. So I followed this article and here is my UI test's code:

import XCTest

class Fastlane_Snapshots: XCTestCase {
    let app = XCUIApplication()

    override func setUp() {
        continueAfterFailure = false
        setupSnapshot(app)
        app.launch()
        addUIInterruptionMonitor(withDescription: "System Dialog") {
            (alert) -> Bool in
            print("Interruption running")
            let button = alert.buttons.element(boundBy: 1)
            if button.exists {
                button.tap()
            }
            return true
        }
        app.tap()
    }

    override func tearDown() {

    }

    func testSnapshots() {

    }
}

But the UI monitor code is never triggered. When I start recording for the testSnapshot method, I see the alert appear in the simulator but it's not dismissed, and when I set a breakpoint on the first line of the UI interruption monitor callback, it doesn't get there.

Any idea what I might have forgotten?

0

There are 0 best solutions below