DevExpress / testcafe

A Node.js tool to automate end-to-end web testing.
https://testcafe.io
MIT License
9.82k stars 673 forks source link

Need to Skip test cases under a fixture If previous test of the same fixture failed #8335

Closed SamShot81 closed 1 day ago

SamShot81 commented 1 week ago

What is your Scenario?

I am working with a situation where I have the following scenario/steps to Test 1) Create 2) Edit 3) Delete

I have the test cases ready but I need a way to skip the Edit and Delete TCs if the Create TC fails. In other words I need to chain them together so the system understands that if Create was not successful then skip the Edit and Delete test cases (Conditional Skipping).

Is it possible with any existing process like hooks/test Context?

Is there any logic I can use to make this happen?

Thanks in Advance.

Expecting something like below

What are you suggesting?

test('Verify Create New Account Functioning Successfully', async (t: TestController) => {
    // if this fails, I can set a variable x=fail
});

test('Verify Edit Account Functioning Successfully', async (t: TestController) => {
    // Skip this as create test case failed
    if(x == fail) {
        test.skip(t.this test);
    }
});

What alternatives have you considered?

Could not find any material regarding this in testcafe documentation.

Additional context

No response

pgusilic-devops commented 4 days ago

Hey, try something like this

import { Selector } from 'testcafe';

let shouldSkip = false;

fixture `My Fixture`
    .beforeEach(async t => {
        if (shouldSkip) {
            await t.skip();
        }
    })
    .afterEach(async t => {
        // Check if the current test failed
        const testFailed = t.testRun.errs.length > 0;

        if (testFailed) {
            shouldSkip = true;
        }
    });

test('Test 1', async t => {
    // Your test logic for Test 1
    // Uncomment this line to simulate a test failure
    // throw new Error("Simulated failure in Test 1");
});

test('Test 2', async t => {
    // This test will be skipped if Test 1 fails
    // Your test logic for Test 2
});

test('Test 3', async t => {
    // This test will also be skipped if any previous test in the fixture fails
    // Your test logic for Test 3
});
Bayheck commented 1 day ago

In TestCafe, you cannot skip a test from inside or use the beforeEach hook for this purpose because the test queue is created at the compilation stage.

Unfortunately, we cannot take this enhancement into work since we are currently focused on other tasks.