[英]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.