While testing your mobile app, it may ask for specific permissions during the test. Various system dialogs or popups may appear, asking the user to grant access.
The mobile app might ask the user permission to access the contacts, notifications, media, ... on the device.
Below we'll go over the various techniques to handle these events during your mobile testing:
On iOS, Appium offers two capabilities which you can use: autoAcceptAlerts and autoDismissAlerts.
autoAcceptAlerts will automatically accept (grant) any alerts (including permission popups) that might appear during your test.
autoDismissAlerts will automatically dismiss (deny) any alerts (including permission popups) that might appear during your test.
caps['autoAcceptAlerts']='true'# to accept all alertscaps['autoDissmissAlerts']='true'# to accept all alerts
caps.setCapability("autoAcceptAlerts","true");// to accept all alertscaps.setCapability("autoDissmissAlerts","true");// to dismiss all alerts
desired_cap={'autoAcceptAlerts':'true',# to accept all alerts
}desired_cap={'autoDissmissAlerts':'true'# to dismiss all alerts
}
varcapabilities={'autoAcceptAlerts':'true'// to accept all alerts}varcapabilities={'autoDissmissAlerts':'true'// to dismiss all alerts}
capability.AddAdditionalCapability("autoAcceptAlerts","true");// to accept all alertscapability.AddAdditionalCapability("autoDissmissAlerts","true");// to accept all alerts
Allow or Deny specific permissions
You can also choose to accept or deny alerts and popups during your test.
Your test will need to find the element of the alert or popup and perform a click action on that element.
# For Androiddriver.find_element(:xpath,".//android.widget.Button[@text='Allow']").click# For iOSdriver.find_element(:id,"Allow").click
// For Androiddriver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();// For iOSdriver.findElement(By.id("Allow")).click();
# For Android
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()# For iOS
driver.find_element_by_id("Allow").click()
// For Androidvarelement=awaitdriver.element("xpath",".//android.widget.Button[@text='Allow']")awaitelement.click()// For iOSvarelement=awaitdriver.element("id","Allow")awaitelement.click()
// For AndroidIWebElementll=driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));ll.Click();// For iOSIWebElementll=driver.FindElement(By.Id("Allow"));ll.Click();
This website uses cookies to ensure you get the best experience on our website. About cookies