AngularJS,带有角度验证码的e2e测试 [英] Angularjs, e2e test with angular-recaptcha

查看:117
本文介绍了AngularJS,带有角度验证码的e2e测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上正在尝试e2e测试我的简单应用程序,并且在处理angular-recaptcha时遇到一些麻烦( https://github.com/VividCortex/angular-recaptcha ).

I'm actually trying to e2e test my simple application and I m having some troubles dealing with angular-recaptcha (https://github.com/VividCortex/angular-recaptcha).

这是我的考试:

  it('should redirect on another page', function() {

    browser.get('http://127.0.0.1:3000/#/');
    var userName = element(by.model('auth.loginInfos.username'));
    userName.sendKeys('consumer1@eco.com');

    var password = element(by.model('auth.loginInfos.password'));
    password.sendKeys('consumer1');



    var recapt = element(by.id('recaptcha'));
    recapt.sendKeys();/* How can I put the recaptcha value to true ? */

    var btn = element(by.className('btn'));
    btn.click();
    /**
     * Assertions etc...
     */

  });

因此,您可以看到我正在尝试填写Recaptcha值,但我不知道如何进行.

So, you can see that I m trying to fill the recaptcha value and I don't know how to proceed.

你能帮我吗?

NB:我正在使用量角器

感谢您的帮助

推荐答案

验证码已加载到iframe中,您需要在尝试检查之前将其切换为

The captcha is loaded in an iframe, you need to switch to it before trying to check:

browser.switchTo().frame(0);

其中,0是帧索引.您可以使用框架名称,id或先前找到的框架元素.

where 0 is a frame index. You can use a frame name, id or a previously found frame element.

使用Recaptcha演示页面的示例测试:

Sample test that uses the recaptcha demo page:

"use strict";

describe("Recaptcha", function () {
    beforeEach(function () {
        browser.ignoreSynchronization = true;
        browser.get("http://vividcortex.github.io/angular-recaptcha/");
    });

    it("should click the captcha", function () {
        browser.switchTo().frame(0).then(function () {
            var checkbox = $(".recaptcha-checkbox-checkmark");

            // first hover the checkbox
            browser.actions().mouseMove(checkbox).perform();

            // hardcoded delay
            browser.sleep(500);

            // okat, now click - TODO: may be we should click with browser.actions().click() and provide the x, y coordinates for where to click
            checkbox.click();
        });

        // expectations
    });
});

请注意,在我的情况下,单击后,它会要求选择某些图像,这些图像完全可以完成不让我的硒自动化机器人通过测试的工作.如果您想实际通过验证码,请根据新的Google reCAPTCHA如何工作?页以及有关此验证码工作原理的已知信息,我将尝试以下操作:

Note that in my case, after the click, it asks to select certain images that would exactly do the job of not letting my selenium automation bot pass the test. If you want to actually pass the captcha, according to the How does new Google reCAPTCHA work? page and the known information about how this captcha works, I would try the following things:

  • 使用您之前使用过的预载配置文件打开浏览器(至少具有浏览历史记录)
  • 在启动测试的浏览器中登录到Google帐户
  • 不要通过click()单击复选框,而要像普通人一样单击带有偏移量的复选框
  • 在浏览器动作之间延迟玩耍
  • open the browser with a pre-loaded profile that you've used before (that has the browsing history, at least)
  • be logged into google account in the browser fired up for testing
  • don't click the checkbox via click() and click it with an offset as a regular human would do
  • play around with a delays between browser actions

另一点是,您无需e2e测试验证码的工作原理-它超出了应用程序的端到端测试范围.找到一种方法来禁用/关闭测试用户或要对其运行测试的特定内部版本的验证码.

Another point is that, you don't need to e2e test how the captcha works - it is out of scope of the end-to-end testing of your application. Find a way to disable/turn the captcha off for the testing users, or for a specific build that you will be running tests against.

这篇关于AngularJS,带有角度验证码的e2e测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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