我正在网上搜索最终的“登录模式”,其中包括验证登录实际上是否成功。问题-我们不允许根据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()
}
}
[没有可行的例子很难说出任何准确的东西。
wait(7000)
看起来有点多余。如果您想确保自己在正确的页面上,可以通过选择器检查元素是否存在。 TestCafe具有内置的等待机制,使您可以避免使用wait
方法:https://devexpress.github.io/testcafe/documentation/test-api/built-in-waiting-mechanisms.html。
您在await
调用之前错过了this.performLogin()
关键字。片状测试的原因可以在这里。
while
语句看起来也很多余,因为您可以将智能断言与客户端函数一起使用。但是,您网站的某些细节似乎迫使您重新加载页面。通常,您不需要在登录后重新加载页面。