testing - 在 fixture.before 钩子中添加 Login 方法会在 Testcafe 中出现错误
问题描述
议程:我想在所有测试之前运行 login 方法,在所有测试之后运行 Logout 方法,这样如果 before 钩子失败,测试执行就不会发生。
我在 fixture.before 钩子中添加了登录逻辑,如下面的代码所示。但它给出了以下错误,可以帮助我修复它。
测试文件
import { Selector } from "testcafe";
import LoginPage from '../page-objects/login.po';
const loginPage = new LoginPage();
fixture`Getting Started`
.page`https://example.com/`
.before(async t => {
await loginPage.login();
});
test("My First Test", async t => {
const str = await Selector('.home-container h1').textContent;
console.log(str);
});
页面对象类
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, '')
.click(this.nextBttn)
.typeText(this.emailTxtBox, '')
.click(this.microsoftNextBttn)
.typeText(this.passwordTxtBox, '')
.click(this.signinBttn)
.click(this.noBttn);
}
}
解决方案
您必须使用beforeEach
夹具挂钩而不是before
https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#fixture-hooks
推荐阅读
- php - 如何将神经网络从 C 转换为 PHP
- android - 首选项库版本 28 在每个首选项的左侧创建巨大的填充
- scala - HList 映射无法定义类型
- recursion - 为什么这不会在 mapcat 中再次发生终止?
- qt - QFontInfo::pixelSize() 在 Qt 4 和 Qt 5 之间变化
- java - Java 应用程序如何知道它在 Docker 容器中运行
- sql - SQL Pivot 分组依据?
- php - Codeigniter Where_In 运算符确实返回任何结果
- c# - SqlTableDependency 保留一些对象并减慢 sql 响应
- python - matplotlib 的不同数据点的不同颜色