codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 724 forks source link

Before / After hooks to be called from tags in bdd scenarios just like in cucumber #3280

Open SamiAkkaya opened 2 years ago

SamiAkkaya commented 2 years ago

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
YakupOguzhanKaya commented 2 years ago

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.

myrepojuly1987 commented 2 years ago

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

});
myrepojuly1987 commented 1 year ago

@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 () {
})
github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 90 days with no activity.