Sometimes when the app/browser under test gets launched for the first time, it displays a Location permission popup or some other popups. Appium has a simple solution to solve this problem, you can use a desired capability specifically designed to handle these alerts.We can handle/ignore these popups by passing the capabilities to Appium driver.
WebDriverWait wait = new WebDriverWait(driver, 1 /*timeout in seconds*/);
int waitTime =0;
while(waitTime <6){
try {
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
} catch (Exception eTO) {
}
waitTime ++;
}
You can either always accept or always dismiss the alerts with these desired capabilities:
Handle popups with capabilities:
- autoAcceptAlertsAccept - All iOS alerts automatically accept if they pop up. This includes privacy access permission alerts (e.g., location, contacts, photos). Default is false
- safariAllowPopups - (Sim-only) Allow javascript to open new windows in Safari. Default keeps current sim setting
- safariIgnoreFraudWarning - (Sim-only) Prevent Safari from showing a fraudulent website warning. Default keeps current sim setting
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("safariAllowPopups", true);
capabilities.setCapability("safariIgnoreFraudWarning", true);
capabilities.setCapability("autoAcceptAlerts", true);
Handle popups with Webdriver Alert :
Another way to handle alerts with Webdriver Alert(),
WebDriverWait wait = new WebDriverWait(driver, 1 /*timeout in seconds*/);
int waitTime =0;
while(waitTime <6){
try {
wait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
} catch (Exception eTO) {
}
waitTime ++;
}
No comments:
Post a Comment