[英]Angularjs, e2e test with angular-recaptcha
我實際上正在嘗試e2e測試我的簡單應用程序,並且在處理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值,但我不知道如何進行。
你能幫助我嗎 ?
注意:我正在使用量角器
謝謝你的幫助
驗證碼已加載到iframe
,您需要在嘗試檢查之前將其切換為:
browser.switchTo().frame(0);
其中0
是幀索引。 您可以使用框架名稱,ID或先前找到的框架元素。
使用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
});
});
請注意,在我的情況下,單擊后,它會要求選擇某些圖像,這些圖像確實可以完成不讓我的硒自動化機器人通過測試的工作。 如果您想實際通過驗證碼,請按照新的Google reCAPTCHA如何工作? 頁以及有關此驗證碼工作原理的已知信息,我將嘗試以下操作:
click()
單擊復選框,而要像普通人那樣以偏移量單擊它 另一點是,您不需要e2e測試驗證碼的工作原理-它超出了應用程序的端到端測試范圍。 找到一種方法來禁用/關閉測試用戶的驗證碼,或者禁用將針對其運行測試的特定內部版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.