【发布时间】:2022-12-09 16:53:15
【问题描述】:
如果我有 3 个测试文件,每个文件都有几个固定装置和测试,就像这样
file1.js
fixture1
test1
test2
fixture2
test3
test4
file2.js
fiture3
test5
test6
fixture4
test7
test8
file3.js
fixture5
test9
test10
test11
fixture6
test12
test13
我发现我可以将fixture.after() 和fixture.before() 用于某个固定装置。我可以使用 test.after() 和 test.before() 进行特定测试。
如果我想给file2.js设置环境,并在file2.js中的所有测试(test5、test6、test7、test8)执行完后clean,testcafe有这样的功能吗?
如果我想为所有文件设置环境,并在所有测试执行时清理它,testcafe有没有这样的功能?
谢谢
更新 1
在阅读了vasily.strelyaev提供的Hooks before and after test runs后,我创建了.testcaferc_seq.js并在package.json中添加了"test": "./node_modules/.bin/testcafe chrome --sf ./integration_tests/file2.js --live --config-file .testcaferc_seq.js"。
.testcaferc_seq.js 是
const utils = require ("integration_tests/utils/afterAllTestRunner.js");
module.exports = {
hostname: "localhost",
...
// before all and after all tests
hooks: {
testRun: {
before: async ctx => {
console.log("---------------- \n before all tests \n ---------------------");
utils.cleanUsers();
},
after: async ctx => {
console.log("---------------- \n after all tests \n ---------------------");
utils.cleanUsers();
},
},
},
}
然而hook并没有起作用,看不到两个console.log(...)的两句话。我错过了什么?
还有一个问题,如果我想控制浏览器(比如chrome)做一些pre/post testRun的步骤,怎么办?
【问题讨论】:
标签: javascript testing automated-tests e2e-testing testcafe