Testcafe-在运行所有夹具后如何运行代码 [英] Testcafe - How to run code after all the fixtures are run
问题描述
我想创建SQL Server数据库的快照,然后在所有固定装置"运行之后将其还原.
I want to create a snapshot of the SQL server DB and then restore it after "all the fixtures" are run.
我可以在每个固定装置之后通过钩住固定装置后进行操作.但是,这在运行测试时会引起问题,因为还原后数据库可能仍处于过渡状态.所以我宁愿在所有固定装置之后做.
I can do it after every fixture through .after hook in a fixture. However, that is causing issues while running tests since the DB may be still in transition after a restore. So I would prefer to do it after all the fixtures.
推荐答案
您还可以使用TestCafe Runner类返回Promise对象.完成所有测试/固定后,您可以使用此对象运行自定义清理代码.
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
这是一个例子:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
})
.then(failedCount => {
// Clean up your database here...
testcafe.close();
});
这篇关于Testcafe-在运行所有夹具后如何运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!