CodeceptJS
CodeceptJS copied to clipboard
Before / After hooks to be called from tags in bdd scenarios just like in cucumber
I want to be able to add value and order parameters to before/after hooks. And values in before/after hooks should be triggered from tags in bdd scenarios.
To execute a specific set of steps before a scenario, I created the method below.
let preConditionTags = [];
Before((test) => {
preConditionTags = test.tags.filter(tags => tags.includes("PC_"))
console.log(preConditionTags)
for (let tag of preConditionTags) {
switch (tag) {
case "@PC_login":
console.log("PC_login executed");
break;
case "@PC_add_user":
console.log("PC_add_user executed");
break;
default:
break;
}
}
});
This can be done natively in cucumber:
@Before(order = 10, value = "@smth" )
public void doSomething(){
// Do something before each scenario
}
Scenario example:
@smth @PC_login @PC_add_user @TD_logout
Scenario: Update added user
Given A new user is created
When I click update user
Then User should be updated
- CodeceptJS version: CodeceptJS v3.3.0
- NodeJS Version: v12.18.3
- Operating System: win 10
- Helper: Playwright
Having the same problem, struggling with this lack of this functionality. Done a lot of search and couldn't find a proper way to do this.
Thanks! I am too looking for the above functionality. @DavertMik @PeterNgTr Is there a way to use tagged hooks as given in the below URL?
https://cucumber.io/docs/cucumber/api/?lang=java#tag-expressions.
Something like as shown below
import {After, Before} from '@cucumber/cucumber'
Before({tags: "@foo"}, ()=>{
// This hook will be executed before scenarios tagged with @foo
});
@PeterNgTr @DavertMik - Hello, is there any chance of having this feature or do you have any suggestions?
Before({tags: '@browser and not @headless'}, async function () {
})
This issue is stale because it has been open for 90 days with no activity.