tes*_*nch 0 javascript authentication testing automation testcafe
我在网上搜索最终的“登录模式”,其中包括登录实际成功的验证。问题 -根据我们在团队中决定的 DRY 和编码约定,我们不允许在 Pagemodels 中使用expect(又名断言)。这是当前的登录方法,有时仍然不稳定。我想问你亲爱的 Automators,你是如何设计包括验证在内的登录的?
/**
* Actual login function
*/
async performLogin(): Promise<void> {
console.log(`perform login`);
await t
.typeText(this.Email, username, {
replace: true,
paste: true
})
.typeText(this.Password, password, {
replace: true,
paste: true
})
.click(this.buttonSignIn)
}
/**
* Login validation
*/
async login(): Promise<void> {
await t.wait(7000)
const getURL: any = ClientFunction(() => window.location.href)
let currentURL: string = await getURL()
while (currentURL === basePM.urlLogin) {
this.performLogin()
await t.eval(() => location.reload(true))
currentURL = await getURL()
}
}
Run Code Online (Sandbox Code Playgroud)
没有一个有效的例子,很难说任何精确的东西。
wait(7000)看起来有点多余。如果您想确保您在正确的页面上,您可以通过选择器检查元素是否存在。TestCafe 有一个内置的等待机制,可以让你避免使用该wait方法:https : //devexpress.github.io/testcafe/documentation/test-api/built-in-waiting-mechanisms.html 。
您await在this.performLogin()通话前错过了关键字。片状测试的原因可能在这里。
该while语句看起来也是多余的,因为您可以对客户端函数使用智能断言。但是,您网站的某些细节似乎迫使您重新加载页面。一般情况下,登录后不需要重新加载页面。
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |