Selenium 自动gmail登录[在oAuth期间]被用户验证阻止
此代码用于登录到gmailSelenium 自动gmail登录[在oAuth期间]被用户验证阻止,selenium,automation,webdriver,gmail,selenium-chromedriver,Selenium,Automation,Webdriver,Gmail,Selenium Chromedriver,此代码用于登录到gmail public void login(User user) { WebDriverWait wait = new WebDriverWait(driver, 60); WebElement emailTextBox = wait.until( ExpectedConditions.visibilityOfElementLocated(By.id("identifierId"))); emailTextBox.sendKey
public void login(User user) {
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement emailTextBox = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("identifierId")));
emailTextBox.sendKeys(user.email);
WebElement nextButton = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(), 'Next')]")));
nextButton.click();
WebElement passwordTextBox = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='password']")));
passwordTextBox.sendKeys(user.password);
nextButton = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[contains(text(), 'Next')]")));
nextButton.click();
}
问题
我们正在测试一个web应用程序,用户可以使用google(oAuth2)登录,但是gmail通过用户验证(重置密码、验证码或电话号码)捕获了自动化脚本
Q:
有没有办法避免gmail用户验证
(我不是要解决google验证挑战,在用户手动运行的普通浏览器中,此验证挑战不会被触发(大多数情况下),但在selenium中,有时会发生这种情况并使我的测试失败。)
2018年8月19日更新
这是一条死胡同,绕过谷歌验证并不是一件小事,在搜索更多信息后,我发现服务虚拟化可能是解决这个问题的正确方法。使用cookies解决了我的问题
公共主页googleAutoLogin(字符串cookieKey,字符串cookieValue){
Calendar cal=Calendar.getInstance();
计算添加(日历小时,1);
Date afterOneHour=cal.getTime();
driver.manage().deleteAllCookies();
Cookie Cookie=新建Cookie.Builder(cookieKey,cookieValue)
.domain(“qreflect.com”)
.path(“/”)
.expiresOn(一小时后)
.Ishtponly(正确)
.build();
driver.manage().addCookie(cookie);
driver.navigate().refresh();
logger.log(Level.INFO,“完成添加cookie”);
归还这个;
}
您必须手动登录一次,然后检查以获取与应用程序会话相关的cookie,将它们存储在某个位置,并将密钥/值对传递给此方法以登录。用户验证要求您做什么?您的代码试用?@DebanjanB我更新了问题。请编辑问题,将其限制为特定问题,并提供足够详细的信息,以确定适当的答案。避免同时问多个不同的问题。请参阅页面以获取澄清此问题的帮助。另外@DebanjanB进行了另一次编辑。