[英]How can we skip the .after steps in TestCafe if the test itself fails?
在我们的项目中,我们在大多数测试和测试文件中使用.beforeEach、.before、.afterEach 和.after。
如果测试步骤失败,我们希望能够跳过测试的 .afterEach 和 .after ,因为很可能在失败后我们将无法成功执行这些步骤。
TestCafe 是否内置了此功能?
谢谢,
您可以使用测试上下文或夹具上下文。 在所有步骤之后在上下文中设置一个特殊值,并在 after 挂钩中检查该值。 如果该值可以接受,则执行钩子的剩余部分; 否则跳过它。 例如:
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.