0

Is there any way to stop all nested describes in case one of the Iterations (Test case) is failing inside one of the nested describes

how to achieve this anyone have any idea

Example

Test
    Describe 1
      it() {}
      Describe 1.1
        It1() {}
        It2() {} (On Error)
        It3() {} (Skip this)
      Describe 1.2 (Skip this)
        It12() {} (Skip this)
        It22() {} (Skip this)
        It33() {} (Skip this)

    Describe 2 (Don't Skip this)
      it() {} (Don't Skip this)
      Describe 1.1
        It21() {} (Don't Skip this)
        It22() {} (Don't Skip this)
        It23() {} (Don't Skip this)
ksk
  • 165
  • 14
  • I'm not sure nesting test steps like this is a good idea, I'm sure it; not the recommended way to split tests. Why do you need them to be nested? – Simon D Nov 29 '22 at 10:07
  • 2
    Does this answer your question? [Skip test in Cypress](https://stackoverflow.com/questions/73581468/skip-test-in-cypress) – Aureuo Nov 29 '22 at 20:14

2 Answers2

0

It can be achieved using the this.skip() method Docs, you can set a flag to indicate a failure, and in the beforeEach hook decide if you want to skip it or not.

here is an example:

describe("my test cases", () => {
  let skipFlag = false;

  Cypress.on("fail", (err, runnable) => {
    skipFlag = true;

    throw err; //keeps the original error
  });
  beforeEach(function () {
    if (skipFlag) {
      this.skip();
    }
  });

  it("a", () => {
    throw {}; //error
  });

  it("b", () => {
    // this will be skipped
    cy.log("hello");
  });
});

Amit Kahlon
  • 108
  • 1
  • 1
  • 10
0

one way to achieve this is using cypress-fail-fast plugin [https://github.com/javierbrea/cypress-fail-fast]

after installing this package

then set the environment variable as

 "FAIL_FAST_STRATEGY": "spec"

in cypress.env.json

that's all

it will work accordingly

ksk
  • 165
  • 14