timjroberts / cucumber-js-tsflow

Provides 'specflow' like bindings for Cucumber.js in TypeScript 1.7+.
MIT License
133 stars 34 forks source link

We haven't ability to set name for @before /@after hooks #10

Closed alexwizp closed 5 years ago

alexwizp commented 8 years ago

After generated html report using the Cucumber JVM plugin, I found that for hooks we see the following names:

Before $step.getName() 000ms After $step.getName() 000ms

What do you think about changing the signature for hooks to: before(name: string, tag?: string, timeout?: number)

If I understand correctly we just need to set name into stepBinding to see the normal report

lsantos10 commented 7 years ago

Also would like to set different timeouts on hooks.

stupiduglyfool commented 7 years ago

I looked at the cucumber-js-tsflow source code, and there are two options for getting the scenario name..

option 1:

` @before() public beforeScenario(): void {

 let world: any = (<any>this)._worldObj;
    let scenarioContext = world.__SCENARIO_CONTEXT;
    let scenarioInfo = <ScenarioInfo> scenarioContext._scenarioInfo;

   console.log(JSON.stringify(scenarioInfo));
}

`

alternatively I've just submitted a pull request https://github.com/timjroberts/cucumber-js-tsflow/pull/19 which sets ScenarioInfo/FeatureInfo

` @before() public beforeScenario(): void {

    console.log(`Before Scenario Hook: "${this.scenarioInfo.scenarioTitle}"`);

    this.scenarioInfo.tags.forEach(tag =>
    {
        console.log(`\tScenario tag: "${tag}"`);
    });

`

Accessing this scenario info should be possible from given/when/then steps also.

timjroberts commented 7 years ago

Will review the PR in the next day or so.

sourabh8003 commented 7 years ago

@timjroberts

I want to use @before() hook for a particular scenario. But it doesn't allow me to do so. In my case, i have a cucumber step file defined for different scenarios, in which i want to perform some operations to be execute before execution of the actual steps for few scenario.

so, is it possible to execute some operation with @before() for specific scenarios? If yes then please give an example.