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 ).
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.
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:
browser.switchTo().frame(0);
where 0
is a frame index. You can use a frame name, id or a previously found frame element.
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
});
});
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:
click()
and click it with an offset as a regular human would do 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.