[英]How can we skip the .after steps in TestCafe if the test itself fails?
In our project, we use.beforeEach, .before, .afterEach, and.after in most of our tests and test files.在我们的项目中,我们在大多数测试和测试文件中使用.beforeEach、.before、.afterEach 和.after。
If a test step fails, we'd like to have the ability to skip the.afterEach and.after of the tests since most likely, we wouldn't be able to execute those steps successfully after a failure.如果测试步骤失败,我们希望能够跳过测试的 .afterEach 和 .after ,因为很可能在失败后我们将无法成功执行这些步骤。
Does TestCafe have this ability built-in? TestCafe 是否内置了此功能?
Thanks,谢谢,
You can use test context or fixture context .您可以使用测试上下文或夹具上下文。 Set a special value in the context after all steps and check this value in the after hook.在所有步骤之后在上下文中设置一个特殊值,并在 after 挂钩中检查该值。 If the value is acceptable, execute the remaining part of the hook;如果该值可以接受,则执行钩子的剩余部分; else skip it.否则跳过它。 For example:例如:
fixture`Fixture`
.page`https://example.com/`
.after((ctx) => {
if (!ctx.success)
return;
console.log('After fixture');
//other code
});
test('Test', async (t) => {
await t.click('non-existed-element');
t.fixtureCtx = { success: true }
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.