Search code examples
swiftxcodexctestxcuitest

How to close System dialogs that appears on app crash?


I'm using xcuitest framework to automate mac application. I get system dialogs when the app is opened again after it crashes. I want to handle the dialog programmatically. But the dialog appears under the process `UserNotificationCenter' instead of the application under test. How can I handle the alert in such case?


Solution

  • You have two options:

    1. Use InterruptionMonitor (documentation, use-case). This approach is however kinda old and I found, that it does not work for all dialogs and situations.
    2. Create a method, which will wait for some regular app's button. If the app's button (or tab bar or other such XCUIElement) is visible and hittable after your app started, you can proceed with your test and if it's not, you can wait for the UserNotificationCenter dialog's button and identify&tap it by its string/position.

    I'm using the second approach and its working much better, than the InterruptionMonitor. But it really depends on your app layout and use-case.