简体   繁体   English

AngularJS,带有角度验证码的e2e测试

[英]Angularjs, e2e test with 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 ). 我实际上正在尝试e2e测试我的简单应用程序,并且在处理angular-recaptcha( https://github.com/VividCortex/angular-recaptcha )时遇到一些麻烦。

Here's my test : 这是我的测试:

  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...
     */

  });

So, you can see that I m trying to fill the recaptcha value and I don't know how to proceed. 因此,您可以看到我正在尝试填充recaptcha值,但我不知道如何进行。

Can you help me ? 你能帮助我吗 ?

NB: I m using protractor 注意:我正在使用量角器

Thanks for your help 谢谢你的帮助

The captcha is loaded in an iframe , you need to switch to it before trying to check: 验证码已加载到iframe ,您需要在尝试检查之前将其切换为:

browser.switchTo().frame(0);

where 0 is a frame index. 其中0是帧索引。 You can use a frame name, id or a previously found frame element. 您可以使用框架名称,ID或先前找到的框架元素。

Sample test that uses the recaptcha demo page: 使用recaptcha演示页面的样本测试:

"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
    });
});

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? 如果您想实际通过验证码,请按照新的Google reCAPTCHA如何工作? page and the known information about how this captcha works, I would try the following things: 页以及有关此验证码工作原理的已知信息,我将尝试以下操作:

  • 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 在启动测试的浏览器中登录到Google帐户
  • don't click the checkbox via click() and click it with an offset as a regular human would do 不要通过click()单击复选框,而要像普通人那样以偏移量单击它
  • play around with a delays between browser actions 在浏览器动作之间延迟播放

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM