议程:我想在所有测试之前运行登录方法,并在所有测试之后运行注销方法,这样,如果before挂钩失败,则不会执行测试。
我在hook.before中添加了登录逻辑,如下面的代码所示。但是它给出了以下错误,可以帮助我修复它。
测试文件
import { Selector } from "testcafe";
import LoginPage from '../page-objects/login.po';
const loginPage = new LoginPage();
fixture`Getting Started`
.page`https://ci360-dev.dynatracelabs.com/`
.before(async t => {
await loginPage.login();
});
test("My First Test", async t => {
const str = await Selector('.home-container h1').textContent;
console.log(str);
});
Pageobjects类
import { Selector, t } from 'testcafe';
import CommonFunctions from '../commons/common-fns'
export default class LoginPage{
constructor () {
this.emailTxtBox = Selector('input[type="email"]');
this.nextBttn = Selector('button[type="submit"]');
this.microsoftNextBttn = Selector('input[type="submit"]');
this.passwordTxtBox = Selector('input[type="password"]');
this.signinBttn = Selector('input[type="submit"]');
this.noBttn = Selector('#idBtn_Back');
}
async login() {
await t
.typeText(this.emailTxtBox, '[email protected]')
.click(this.nextBttn)
.typeText(this.emailTxtBox, '[email protected]')
.click(this.microsoftNextBttn)
.typeText(this.passwordTxtBox, 'Dynatrace2019')
.click(this.signinBttn)
.click(this.noBttn);
}
}
您必须使用beforeEach
夹具挂钩而不是before
https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#fixture-hooks