简体   繁体   中英

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.

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.

Does TestCafe have this ability built-in?

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. 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 }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM