簡體   English   中英

如果測試本身失敗,我們如何跳過 TestCafe 中的 .after 步驟?

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM