无法使用 PageObjects 在 TestCafe 中从 .before 打开 Url (.navigateTo)
Unable to open Url (.navigateTo) from .before in TestCafe using PageObjects
我是 JS 和 TestCafe 的新手。
在 TestCafe 中使用 PageObjects 我的目标是在 运行 测试之前启动登录页面并进行身份验证。
.open 调用在固定装置中工作正常。也来自 with .before.
fixture `Check for new emails`
.page `https://www.mail.com/myemails`
和
fixture `Check for new emails`
.page `https://www.mail.com/myemails`
.beforeEach(async t => {
console.log("before");
.page `https://www.mail.com/login`;
myloginScreen.performLogin();
})
test ('', async t => {
await t
console.log("In the test step");
});)
页面对象看起来像这样:
import { Selector, t } from 'testcafe';
export default class LoginPage {
constructor () {
this.loginInput = Selector('input').withAttribute('id','email');
this.passwordInput = Selector('input').withAttribute('id','password');
this.signInButton = Selector('button').withAttribute('class','big-button');
this.userMenu = Selector('a').withAttribute('data-which-id', 'gn-user-menu-toggle-button');
}
async performLogin() {
console.log("function entered")
.typeText(this.loginInput, 'user@mail.com')
.typeText(this.passwordInput, 'password')
.click(this.signInButton);
console.log("Form submitted");
}
}
但我想像这样将登录 URL 加载移动到 PageObject:
async performLogin() {
console.log("function entered")
.navigateTo ("https://www.mail.com/login")
await t
.typeText(this.loginInput, 'user@mail.com')
.typeText(this.passwordInput, 'password')
.click(this.signInButton);
console.log("Form submitted");
}
代码调用函数正常,但退出 .before 并跳转到测试步骤。
我不确定我在这里做错了什么,将不胜感激任何帮助。
performLogin
是一个异步方法。因此,您需要使用 await
关键字来调用它:
fixture `Check for new emails`
.page `https://www.mail.com/myemails`
.beforeEach(async t => {
console.log("before");
await myloginScreen.performLogin();
});
我是 JS 和 TestCafe 的新手。
在 TestCafe 中使用 PageObjects 我的目标是在 运行 测试之前启动登录页面并进行身份验证。
.open 调用在固定装置中工作正常。也来自 with .before.
fixture `Check for new emails`
.page `https://www.mail.com/myemails`
和
fixture `Check for new emails`
.page `https://www.mail.com/myemails`
.beforeEach(async t => {
console.log("before");
.page `https://www.mail.com/login`;
myloginScreen.performLogin();
})
test ('', async t => {
await t
console.log("In the test step");
});)
页面对象看起来像这样:
import { Selector, t } from 'testcafe';
export default class LoginPage {
constructor () {
this.loginInput = Selector('input').withAttribute('id','email');
this.passwordInput = Selector('input').withAttribute('id','password');
this.signInButton = Selector('button').withAttribute('class','big-button');
this.userMenu = Selector('a').withAttribute('data-which-id', 'gn-user-menu-toggle-button');
}
async performLogin() {
console.log("function entered")
.typeText(this.loginInput, 'user@mail.com')
.typeText(this.passwordInput, 'password')
.click(this.signInButton);
console.log("Form submitted");
}
}
但我想像这样将登录 URL 加载移动到 PageObject:
async performLogin() {
console.log("function entered")
.navigateTo ("https://www.mail.com/login")
await t
.typeText(this.loginInput, 'user@mail.com')
.typeText(this.passwordInput, 'password')
.click(this.signInButton);
console.log("Form submitted");
}
代码调用函数正常,但退出 .before 并跳转到测试步骤。
我不确定我在这里做错了什么,将不胜感激任何帮助。
performLogin
是一个异步方法。因此,您需要使用 await
关键字来调用它:
fixture `Check for new emails`
.page `https://www.mail.com/myemails`
.beforeEach(async t => {
console.log("before");
await myloginScreen.performLogin();
});