Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 自动gmail登录[在oAuth期间]被用户验证阻止_Selenium_Automation_Webdriver_Gmail_Selenium Chromedriver - Fatal编程技术网

Selenium 自动gmail登录[在oAuth期间]被用户验证阻止

Selenium 自动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

此代码用于登录到gmail

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进行了另一次编辑。