我是E2E测试的初学者,我想使用TestCafe对github帐户测试进行e2e注册,但是运行测试时出现此错误:
ExternalAssertionLibraryError {
code: 'E53',
isTestCafeError: true,
callsite:
CallsiteRecord {
filename: 'TestCafe\\authentication.page.js',
lineNum: 152,
callsiteFrameIdx: 6,
stackFrames:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
CallSite {},
[Object],
[Object],
[Object],
[Object],
CallSite {} ],
isV8Frames: true },
errMsg: 'AssertionError: expected false to be truthy'
}
这是我的代码authentication.page.js
:
import { Selector, t } from 'testcafe';
export default class AuthenticationPage {
constructor(){
//add page elements to our page model
//select sign up form elements
this.username = Selector('#user_login');
this.user_email= Selector('#user_email');
this.user_password = Selector('#user_password');
this.signup_form = Selector('#signup-form');
this.registerBtn = Selector('#signup_button');
//continue button
this.continue_btn = Selector('.btn.btn-primary.js-choose-plan-submit');
}
//create a new github account
async register(){
/**
* Step 1:
* Set up your account
* first thing to do is checking for the form
*/
await t
.setTestSpeed(0.1)
.expect(this.signup_form.exists).ok()
.expect(this.signup_form.getAttribute('method')).eql('post')
.expect(this.signup_form.getAttribute('action')).eql('/join')
.catch((error) => {
console.error(error);
});
// input elements
await t
.setTestSpeed(0.1)
// username input check
.expect(this.username.exists).ok()
.expect(this.username.getAttribute('type')).eql('text')
.expect(this.username.value).eql('')
// email input check
.expect(this.user_email.exists).ok()
.expect(this.user_email.getAttribute('type')).eql('text')
.expect(this.user_email.value).eql('')
// password input check
.expect(this.user_password.exists).ok()
.expect(this.user_password.getAttribute('type')).eql('password')
.expect(this.user_password.value).eql('')
.catch((error) => {
console.error(error);
});
// fill out the inputs
await t
.setTestSpeed(0.1)
.typeText(this.username, 'some username')
.expect(this.username.getAttribute('class')).eql('form-control is-autocheck-successful')
.typeText(this.user_email, 'some email')
.expect(this.user_email.getAttribute('class')).eql('form-control is-autocheck-successful')
.typeText(this.user_password, 'some password')
.catch((error) => {
console.log(error);
});
// Captcha verification
await t
.expect(await Selector('svg[class="octicon octicon-check text-green"]').exists).ok()
.catch((error) => {
console.log(error);
});
await t
.setTestSpeed(0.1)
// Input data check
.expect(this.username.value).contains('some username')
.expect(this.user_email.value).contains('some email')
.expect(this.user_password.value).contains('some password')
// Singup Check
.expect(this.registerBtn.exists).ok()
.expect(this.registerBtn.getAttribute('type')).eql('submit')
.click(this.registerBtn)
.catch((error) => {
console.error(error);
});
/**
* Step 2:
* Choose your plan
*/
await t
.expect(this.continue_btn.exists).ok()
.expect(this.continue_btn.getAttribute('type')).eql('submit')
.click(this.continue_btn)
.catch((error) => {
console.log(error);
});
/**
* Step 3:
* Tailor your experience
*/
const prog_exp_level = Selector('#answers_98_choice_476');
const github_uses_plan = Selector('#answers_99_choice_468');
const describe = Selector('#answers_100_choice_472');
const submit_btn = Selector('input[type="submit"]')
await t
.setTestSpeed(0.1)
.expect(prog_exp_level.exists).ok()
.expect(prog_exp_level.getAttribute('type')).eql('radio')
.click(prog_exp_level)
.expect(github_uses_plan.exists).ok()
.expect(github_uses_plan.getAttribute('type')).eql('checkbox')
.click(github_uses_plan)
.expect(github_uses_plan.checked).ok()
.expect(describe.exists).ok()
.expect(describe.getAttribute('type')).eql('radio')
.click(describe)
.expect(submit_btn.exists).ok()
.click(submit_btn)
.catch((error) => {
console.log(error);
});
}
}
在此文件中,我调用了注册功能register.test.js
:
// import the testcafe module
import { Selector, ClientFunction} from 'testcafe';
import AuthenticationPage from './authentication.page';
const page = new AuthenticationPage();
//declare a fixture
fixture `Github Signup Test`
.page `https://github.com/join`;
//create login test code
test
.before( async t => {
const link = await Selector('a').withText('Sign up');
if(await link.exists && await link.visible){
await t
.click(link)
.catch((error) => {
console.error(error);
});
}
})
('register test', async t => {
await page.register();
})
.after( async t => {
console.log('test..');
});
在进行测试时,我发现无法验证验证码。 我需要知道如何解决这个问题 有任何帮助的想法吗?
答案 0 :(得分:3)
哼...,
首先,验证码嵌套在两个iframe中。你必须切换 解释这些iframe here。
然后,您必须按照here中的说明拍摄验证码的屏幕快照;
然后,您必须创建和训练神经网络以识别如何 图片已放置:您可以使用 TensorFlow为此目的