iOS 13 | Handle privacy pop-ups in automation tests
With iOS 13, Apple has introduced further hardening of privacy and security settings. Part of this is the addition of new system popups that give users better control over their privacy. This includes popup notifications to verify that users approve app access to location, contacts, and photos while the app is open or working in the background. Because these popups may disrupt automation flows, your implementation should be aware of such popups and have an effective handling mechanism.
These are examples of the most common prompts, followed by proposed solutions:
-
Prompts for permission to access location, contacts, or photos while using the apps
-
Prompts for permission to access location, contacts, or photos when the app is running in the background
-
Prompts that request use of known nearby Wi-Fi networks or Bluetooth devices
To mitigate such behavior in your automated tests with Perfecto, you can:
-
Add the
autoAcceptAlerts
orautoDismissAlerts
capability to the driver with a value oftrue
that accepts (or rejects) all access requests during test execution.For example:
The current behavior of
autoDismissAlerts
andautoAcceptAlerts
is counter-intuitive when it comes to popups with more than two buttons. For such popups, if you want to automatically:- Dismiss alerts: Use
autoAcceptAlerts
. - Accept alerts: Use
autoDismissAlerts
.
- Dismiss alerts: Use
-
Use a simple try-catch pattern to accept alerts when they are expected to pop up in your test by finding the Allow buttons with a generic locator.
For example:
Copytry {
getDriver().findElementByXPath("//*[contains(@label,'Allow While Using')]").click();
} catch (Exception e) {
e.printStackTrace();
}