How to handle alert in UITests in iOS
Issue #82
Usually in an app, you have the onboarding with steps that require push notification and location permission to be turned on. And you want to automate these steps via UITests
Firstly, you need to add interruption handler
1 | addUIInterruptionMonitor(withDescription: "Alert") { |
Then you need to call tap
on XCUIApplication
to make the app responsive
1 | turnOnPushNotificationButton.tap() |
Sometimes the alert handling is slow and you get Did not receive view did disappear notification within 2.0s
. Well, the workaround is to wait for the element on next onboarding step to appear. Starting with Xcode 9, you can use waitForExistence
.
This is how you can go to last step after user has enabled push notification
1 | let label = staticTexts["Congratulation. You've granted us permission. Now enjoy the app."] |