You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The description under the link you sent suggests that these lifecycle test hook go for the specific step implementation
// inside step_definitionsBefore((test)=>{// perform your codetest.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
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
});
}
Activity
kobenguyent commentedon Oct 21, 2024
please check this https://codecept.io/bdd/#before, hope this helps @attilagyoriid
and https://codecept.io/bdd/#advanced-gherkin
attilagyoriid commentedon Oct 22, 2024
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
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
kobenguyent commentedon Oct 22, 2024
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
});
}
attilagyoriid commentedon Oct 22, 2024
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
kobenguyent commentedon Oct 22, 2024
@attilagyoriid would you mind sharing the use case where you need that for? I'm not sure I could help but that would be helpful for community