0

I was wondering if there is a way to wrap some of the cucumber scenarios inside one context same as in mocha in order to use a certain hook such as beforeAll,

        before(() => {
             this will run once beforeAll
        });
    it('01. example', () => {
             do something
       });

    context('05. Forget password Tests', () => {
        before(() => {
             this will run once beforeAll
        });

        it('05-1. should get an error when no email is provided', () => {
              do somthing
        });
)}

since the alternative option is to use before with tags but this will act similar to beforeEach and it will run before each scenario, the scenario above shows to before hook first one will run once before context and 2nd will run once before all it blocks inside the context and this what I want to achieve in cucumber.

1 Answers1

0

Whenever you start to program in cucumber features you are invariably doing something wrong. You should program either above the features by calling cucumber several times (rarely needed) or program below cucumber by calling helper methods from step definitions.

You should never be trying to have things persist between scenarios or use one scenario to setup state for another scenario. Taking that path results in a very fragile suite of tests that is difficult to maintain and optimise. Instead follow the standard cucumber approach of having each scenario/test start and end with a clean slate.

diabolist
  • 3,990
  • 1
  • 11
  • 15