I am developing automation scripts using selenium webdirver, Appium for Mobile website automation.
Previously for the website I automate there is no authentication popup asked. Now for all the lower environments authentication is asked.
So how do I handle user authentication popup.
Technologies I use are java, selenium and appium for both Android and iOS platforms.
Can anyone help me out.
You can get xpath/id of popup element and buttons , using these you can perform action on these buttons.
@findby(id="android/button1")
WebElement allow_button;
public void clickonAllow()
{
allow_button.click();
}
As per requirement you can click on button "Allow" / "Deny" or "Accept" or "Reject"
In web you can try driver.switchTo().alert().accept();
or driver.switchTo().alert().deny();
I had similar issue just a while ago, with allowing locations. This issue should be divided into platform specific
for iOS is bit more specific and it has code like this:
driver.findElement(By.xpath("//XCUIElementTypeAlert//XCUIElementTypeButton[@name='Allow']")).click();
(if You have for eg. 'Allow' button)
and for Android You can break them into elements, here is a code example from my code:
public class Alert implements org.openqa.selenium.Alert
@AndroidFindBy(id = "com.android.packageinstaller:id/dialog_container")
@WithTimeout(time = 3, unit = TimeUnit.SECONDS)
public MobileElement alertControl;
@AndroidFindBy(id = "com.android.packageinstaller:id/permission_message")
@WithTimeout(time = 3, unit = TimeUnit.SECONDS)
private MobileElement content;
@AndroidFindBy(id = "com.android.packageinstaller:id/permission_allow_button")
@WithTimeout(time = 3, unit = TimeUnit.SECONDS)
private MobileElement buttonAccept;
@AndroidFindBy(id = "com.android.packageinstaller:id/permission_deny_button")
@WithTimeout(time = 3, unit = TimeUnit.SECONDS)
private MobileElement buttonDismiss;
public Alert(SessionInfo sessionInfo){
super(sessionInfo);
PageFactory.initElements(new AppiumFieldDecorator(sessionInfo.getMobileDriver(), 3, TimeUnit.SECONDS), this)
WaitUtils.isElementPresent(sessionInfo.getMobileDriver(),alertControl,2);
if (!Util.areElementsLoaded(alertControl, content, buttonAccept, buttonDismiss)) {
setLoaded(false);
} else {
setLoaded(true);
}
Validate.isScreenLoaded(getSessionInfo(), this.isLoaded());
}
@Override
public void dismiss() {
buttonDismiss.click();
Validate.action(getSessionInfo(), "ALERT - click button 'Dismiss'");
}
@Override
public void accept() {
buttonAccept.click();
Validate.action(getSessionInfo(), "ALERT - click button 'Accept'");
}
@Override
public String getText() {
String value = content.getText();
Validate.action(getSessionInfo(), "ALERT - get content");
return value;
}
@Override
public void sendKeys(String s) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.