Dismiss alerts on iOS/XCUitest

Target :iOS and XCUITest
Native application

On some devices I get loads and loads of “alerts”, not caused directly by the app under test, but they often are in the background , for example a device that we intentionally have not upgraded from ioS 9 to 10, I get an upgrade alert. I also get alerts telling me to login to the apple appstore and various mailboxes too. I could reduce these alerts, but the test engine gets blocked by them even if I eliminate 90% of them, it’s still not really useful. Especially if when a test fails/blows up, that an alert is likely. (apple store login get caused by the app talking to the store, but normally the test handles that. its when a test crashes that its a problem.)

“The test runner failed to initialize for UI testing. (Underlying error: Failed to background test runner within 30.0s.)”

This feels like a bug in the apple drivers, or a capability they have which is undocumented. I have been scanning a few threads that talk about an “autoacceptallerts” capability, but no docs.

1 Like

autoAcceptAlerts/autoDismissAlerts capabilities only work if the test is already running on the device. There is no possibility to dismiss system alerts before the server starts and yes, such alerts block the application startup unless handled manually. I saw different approaches on how to handle them, for example one can disable network access to Apple update servers in order to avoid iOS upgrade popup, use device provisioning policies or use facebook-idb tool to perform ui operations. What I can say for sure is that such issue exists for quite a while, but nothing was done from Apple side to address it. Good luck in trying these workarounds.

1 Like

Yes, this helped, we had an issue with an alert that was left over from a prior test run (even after uninstalling the app) and we have opted to rather handle alerts explicitly on a “per occurrence” basis now. This so far is working better than using the auto acceptallerts parameter for making sure we are noting when alerts we actually expected as well.