john-doherty/selenium-cucumber-js

How to use the before/after hooks?

edento opened this issue · 5 comments

I have read the readme file, but I do not understand where those should be located.
lets take an example, I want to print the name of the feature before each feature.

// before-hook.js
module.exports = function () {
    // add a before feature hook
    this.BeforeFeature(function(feature, done) {
        console.log('BeforeFeature: ' + feature.getName());
        done();
    });
};
  1. that means this code will run before each feature?
  2. what is done?
  3. where should before-hooks.js should be located? (features folder? else?

Thanks!

Hi @edento, done it just a callback function. It could be called callback. When you execute this function you're telling the framework you've completed that task.

@Temi89 where do you place the before hooks?

@john-doherty Thanks. where should i located that hook? a different file? will your package will automatically include it or it needs a specific location?

EdamL commented

@edento I tried the hooks in the step definitions file and in a world.js file in my step_definitions folder. They both seem to work.

Hello @john-doherty! I try to use different BeforeScenario in different features with different step-definitions files, but when I started npm test I see that I used only one BeforeScenario and part of my test failed

Closing as this is super old. Please reopen if its still an issue