Codeceptjs - BDD approach - Before all scenarios are run

133 views Asked by At

I have codeceptjs tests written in BDD format (Scenarios with tags). I have clubbed tests into few groups (based on tags) and run them in parallel in Travis

I would like to run a set of browser actions (say, create prerequisite for all tests) before all scenarios are run.

Is there a way to do this?

PS: I read about BeforeSuite but seems to be at file level and also doesnt have browser access

1

There are 1 answers

0
Sandeep Kumar On

You can make use of Event listeners in your hooks file to achieve this.

const event = require('codeceptjs').event;

module.exports = function() {
  event.dispatcher.on(event.all.before, function () {
    console.log('--- I am before all --');
    // your pre-requisite steps goes here
  });
}

This event runs before running any type of test in codeceptjs and hence you can add your pre-requisite steps in here.