自动进行Gmail登录[在oAuth期间]用户验证阻止了Gmail登录 [英] Automating gmail login [During oAuth] gets blocked with user verification

查看:217
本文介绍了自动进行Gmail登录[在oAuth期间]用户验证阻止了Gmail登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码可用于登录gmail

This code works to login to 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会捕获带有用户验证(重置密码或验证码或电话号码)的自动化脚本.

We have a web application under test where users can login with google (oAuth2), however gmail traps automation script with a user verification (reset password or captcha or phone number).

问:

有什么方法可以避免Gmail用户验证?

Is there any way to avoid gmail user verification ?

(我不是要解决Google验证挑战,在用户手动运行的普通浏览器中,该验证挑战不会触发(大多数情况下),但是使用硒,它有时会发生并且无法通过我的测试.)

(I am not asking to solve google verification challenge, in normal browser run by user manually this verification challenge doesn't get triggered (most of times), but with selenium it sometimes happens and fails my tests.)

更新19.08.2018

这是一个死胡同,绕过google验证并非易事,在搜索更多信息后,我发现服务虚拟化是解决此问题的正确方法,可能是

This is a dead end, bypassing google verification is not trivial, upon searching more I found that service virtualization is the correct way to solve this issue, possibly Hoverfly.

推荐答案

使用cookie解决了我的问题

Using cookies solved my issue

public HomePage googleAutoLogin(String cookieKey, String cookieValue) {
    Calendar cal = Calendar.getInstance();
    Date today = cal.getTime();
    cal.add(Calendar.HOUR, 1);
    Date afterOneHour = cal.getTime();

    driver.manage().deleteAllCookies();

    Cookie cookie = new Cookie.Builder(cookieKey, cookieValue)
            .domain("qreflect.com")
            .path("/")
            .expiresOn(afterOneHour)
            .isHttpOnly(true)
            .build();

    driver.manage().addCookie(cookie);
    driver.navigate().refresh();
    logger.log(Level.INFO, "Finished adding cookie");

    return this;
}

您必须手动登录一次,然后检查以获取与您的应用会话相关的cookie,将它们存储在某个地方并传递密钥,此方法的值以进行登录.

you have to login manually once then inspect to get cookies related to you app session, store them somewhere and pass key, value to this method to get logged in.

这篇关于自动进行Gmail登录[在oAuth期间]用户验证阻止了Gmail登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆