Handle permission pop-ups

This article explains how to handle app permissions during mobile test automation.

While testing different scenarios, its common for iOS or Android apps to show various pop-ups or system dialogs that prompt the user to grant various permissions (e.g. contacts, notifications, photos etc) to the app. There are various techniques to handle these interactions during automated test execution.

1. Grant all permissions for Android apps

To test Android apps, use Appium’s autoGrantPermissions capability to automatically determine which permissions your app requires and grant them to the app on install. These permissions are determined based on the Android manifest defined in the the app’s .APK file. This cabability works on Appium 1.9.1 and above.

The sample below shows how to use autoGrantPermissions capability for your Android tests:

caps.setCapability("autoGrantPermissions", "true");
let capabilities = {
    'autoGrantPermissions': 'true'
}
capability.AddAdditionalCapability("autoGrantPermissions", "true");
desired_cap = {
  'autoGrantPermissions' = 'true',
}
caps['autoAcceptAlerts'] = 'true'
Note: If noReset cabability is set to true, autoGrantPermissions capability doesn’t work.

2. Allow or deny all permissions for iOS apps

To test iOS apps, use Appium’s autoAcceptAlerts and autoDismissAlerts capabilities to handle app permissions. autoAcceptAlerts will automatically accept all permission pop-ups. autoDismissAlerts will automatically dismiss all permission pop-ups. This includes privacy access permission pop-ups (e.g., location, contacts, photos).

The sample below shows how to use autoAcceptAlerts or autoDissmissAlerts capabilities for your test:

caps.setCapability("autoAcceptAlerts", "true"); //to accept all alerts
//OR
caps.setCapability("autoDissmissAlerts", "true"); //to dismiss all alerts
let capabilities = {
    'autoAcceptAlerts': 'true' //to accept all alerts
}
//OR
let capabilities = {
    'autoDissmissAlerts': 'true' //to dismiss all alerts
}
capability.AddAdditionalCapability("autoAcceptAlerts", "true"); //to accept all alerts
//OR
capability.AddAdditionalCapability("autoDissmissAlerts", "true"); //to accept all alerts
desired_cap = {
  'autoAcceptAlerts': 'true', #to accept all alerts
}
#OR
desired_cap = {
  'autoDissmissAlerts': 'true' #to dismiss all alerts
}
caps['autoAcceptAlerts'] = 'true' #to accept all alerts
#OR
caps['autoDissmissAlerts'] = 'true' #to accept all alerts
Note: For iOS 13 & above, pop-ups can have more than two buttons. When there are more than two buttons on popups, autoDismissAlerts and autoAcceptAlerts behaviour is flipped. For such popups, use autoAcceptAlerts to automatically dismiss all popups and autoDismissAlerts to automatically accept all popups.

3. Allow or Deny any permission pop-up for Android and iOS apps

For more selective test scenarios, you can accept some app permission pop-ups and deny the others. To automate these interactions,you can accept or deny individual pop-ups by finding their respective element locators on iOS and Android devices.

//For Android
driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
//For iOS
driver.findElement(By.id("Allow")).click();
//For Android
let element = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
await element.click();
//For iOS
let element = await driver.element("id", "Allow")
await element.click();
//For Android
IWebElement ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
ll.Click();
//For iOS
IWebElement ll =  driver.FindElement(By.Id("Allow"));
ll.Click();
#For Android
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
#For iOS
driver.find_element_by_id("Allow").click()
#For Android
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
#For iOS
driver.find_element(:id, "Allow").click;

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert