CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

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

Open SamiAkkaya opened this issue 2 years ago • 4 comments

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

SamiAkkaya avatar Apr 01 '22 07:04 SamiAkkaya

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.

YakupOguzhanKaya avatar Apr 01 '22 07:04 YakupOguzhanKaya

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 avatar Oct 13 '22 17:10 myrepojuly1987

@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 () {
})

myrepojuly1987 avatar Nov 30 '22 09:11 myrepojuly1987

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

github-actions[bot] avatar Dec 15 '23 02:12 github-actions[bot]