【问题标题】:How can we skip the .after steps in TestCafe if the test itself fails?如果测试本身失败,我们如何跳过 TestCafe 中的 .after 步骤?
【发布时间】:2022-08-15 15:24:53
【问题描述】:

在我们的项目中,我们在大多数测试和测试文件中使用 .beforeEach、.before、.afterEach 和 .after。

如果测试步骤失败,我们希望能够跳过测试的 .afterEach 和 .after ,因为很可能在失败后我们将无法成功执行这些步骤。

TestCafe 是否内置了此功能?

谢谢,

    标签: javascript testing automation automated-tests testcafe


    【解决方案1】:

    您可以使用test contextfixture context。在所有步骤之后在上下文中设置一个特殊值,并在 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 }
    })
    

    【讨论】:

      猜你喜欢
      • 2018-06-12
      • 1970-01-01
      • 2020-06-19
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多