Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BDD gherkin test hooks dont get triggered #4558

attilagyoriid started this conversation in General
Discussion options

What are you trying to achieve?

wire up bdd test hooks like const { Before, After, BeforeAll, AfterAll } = require('@cucumber/cucumber');

What do you get instead?

hooks dont get triggered

Provide test source code if related

testHooks.js content:
const { Before, After, BeforeAll, AfterAll } = require('@cucumber/cucumber');
BeforeAll(() => {
console.log('Global setup before all tests');
});
AfterAll(() => {
console.log('Global teardown after all tests');
});
Before(() => {
console.log('Running setup before each test');
});
After(() => {
console.log('Running cleanup after each test');
});

Details

  • CodeceptJS version: 3.6.7
  • NodeJS Version: v20.11.0
  • Operating System: macOS 15.0.01
  • puppeteer || webdriverio || testcafe version (if related)
  • Configuration file:
codecept.conf.js
gherkin: {
 hooks: './codeceptjs/testHooks.js',
 features: '../features/**/*.feature',
 steps: '../src/steps/**/*_steps.js',
},
 testHooks.js not even called, and lifecycle methods not triggered

question: how to hook up bdd hooks? - in this case I needed a BeforeAll hook as a global hook

Thanks for the guidance in advance

Best Regards

Attila

You must be logged in to vote

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

Dear @kobenguyent

thank you very much for your answer.

The description under the link you sent suggests that these lifecycle test hook go for the specific step implementation

// inside step_definitions
Before((test) => {
 // perform your code
 test.retries(3); // retry test 3 times
});"

Question:

How can achieve a "BeforeAll" lifecycle hook running before each and every scenarios located in any step implementation file? So basically a hook running before all features

Best Regards

Attila

You must be logged in to vote
0 replies
Comment options

I'm not really understanding much the bdd implementation but I think you could achieve this by using event listeners

For example

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
});
}

You must be logged in to vote
0 replies
Comment options

Dear @kobenguyent thanks for the quick reply again

I would need a global life cycle hook where I can use I actor. Is there any hook like that?

Best Regards

Attila

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Converted from issue

This discussion was converted from issue #4521 on November 11, 2024 14:39.

AltStyle によって変換されたページ (->オリジナル) /