Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy
No Result Found

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.

If you are using BrowserStack SDK, you can set the following capability within the browserstack.yml file:

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:

Capability Description Values
autoGrantPermissions Grant all permissions for Android apps true
browserstack.yml
Copy icon Copy

The autoGrantPermissions capability doesn’t work if noReset cabability is set to true.

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 autoDismissAlerts capabilities for your test:

Capability Description Values
autoAcceptAlerts Allow all permissions for iOS apps true
autoDismissAlerts Deny all permissions for iOS apps true
browserstack.yml
Copy icon Copy

or

browserstack.yml
Copy icon Copy

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.

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

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:

Capability Description Values
autoGrantPermissions Grant all permissions for Android apps true
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("autoGrantPermissions", "true");
var capabilities = {
        "autoGrantPermissions" : "true"
    }
AppiumOptions capabilities = new AppiumOptions();
capabilities.AddAdditionalCapability("autoGrantPermissions", "true");
desired_cap = {
      "autoGrantPermissions" = "true"
  }
capabilities = {
       "autoGrantPermissions" => "true"
    }
caps.setCapability("autoGrantPermissions", "true");
let capabilities = {
    'autoGrantPermissions': 'true'
}
capability.AddAdditionalCapability("autoGrantPermissions", "true");
desired_cap = {
  'autoGrantPermissions' = 'true',
}
caps['autoAcceptAlerts'] = 'true'

The autoGrantPermissions capability doesn’t work if noReset cabability is set to true.

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 autoDismissAlerts capabilities for your test:

Capability Description Values
autoAcceptAlerts Allow all permissions for iOS apps true
autoDismissAlerts Deny all permissions for iOS apps true
DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("autoAcceptAlerts", "true"); //to accept all alerts

//OR

DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("autoDismissAlerts", "true"); //to dismiss all alerts
var capabilities = {
 	'bstack:options' : {
        "autoAcceptAlerts" : "true"
    },
}
//to accept all alerts

//OR

var capabilities = {
 	'bstack:options' : {
        "autoDismissAlerts" : "true"
    },
}
//to dismiss all alerts
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("autoAcceptAlerts", "true"); //to accept all alerts

//OR

AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("autoDismissAlerts", "true"); //to dismiss all alerts
desired_cap = {
 	'bstack:options' : {
      "autoAcceptAlerts" = "true",
  },
}
#to accept all alerts

#OR

desired_cap = {
 	'bstack:options' : {
      "autoDismissAlerts" = "true",
  },
}
#to dismiss all alerts
capabilities = {
    'bstack:options' => {
       "autoAcceptAlerts" => "true"
    },
}
#to accept all alerts

#OR

capabilities = {
    'bstack:options' => {
       "autoDismissAlerts" => "true"
    },
}
#to dismiss all alerts
caps.setCapability("autoAcceptAlerts", "true"); //to accept all alerts
//OR
caps.setCapability("autoDismissAlerts", "true"); //to dismiss all alerts
let capabilities = {
    'autoAcceptAlerts': 'true' //to accept all alerts
}
//OR
let capabilities = {
    'autoDismissAlerts': 'true' //to dismiss all alerts
}
capability.AddAdditionalCapability("autoAcceptAlerts", "true"); //to accept all alerts
//OR
capability.AddAdditionalCapability("autoDismissAlerts", "true"); //to dismiss all alerts
desired_cap = {
  'autoAcceptAlerts': 'true', #to accept all alerts
}
#OR
desired_cap = {
  'autoDismissAlerts': 'true' #to dismiss all alerts
}
caps['autoAcceptAlerts'] = 'true' #to accept all alerts
#OR
caps['autoDismissAlerts'] = 'true' #to dismiss all alerts

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.

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
Download Copy Check Circle