cypress-cucumber-preprocessor icon indicating copy to clipboard operation
cypress-cucumber-preprocessor copied to clipboard

Is it possible to get Scenario details (name, tags, etc.) if After method?

Open vikmaksymenko opened this issue 6 years ago • 6 comments

Hi, I'm using Cypress with cypress-cucumber-preprocessor and want to integrate it with TestRail. I was going to add test case id as tag to scenarios, but looks like test result object is not provided to After method (unlike Cucumber.js). Is there any way to handle this situation, thanks?

vikmaksymenko avatar Dec 12 '19 09:12 vikmaksymenko

Workaround Following code can be added to lib/createTestFromScenario.js in runTest() to get the current scenario detail Cypress.env('currentScenario', scenario);

amitguptagwl avatar Jan 02 '20 12:01 amitguptagwl

+1 on this request. I was able to try the workaround and it works, but don't want to modify it in node_modules.

BTW, this tool is awesome! Thank you!

Maxiiimus avatar Feb 04 '20 23:02 Maxiiimus

Picking up on @amitguptagwl 's suggestion - the current scenario detail is already available during the time that the scenario is being run without needing to patch node_modules.

window.testState.currentScenario

Also, from within a cucumber After block the results of the steps executed during the scenario can be obtained from

window.testState.stepResults

jcundill avatar Feb 26 '20 21:02 jcundill

It would be nice to make custom World overriding possible. Anyway for scenario results there is a cucumber way to obtain scenario results (works in Protractor, but unfortunately in this preprocessor). You could try adding it if possible:

Custom World class:

export class World {
    constructor() {}

    testFunction() {
        console.log('From testFunction()');
    }
}

setWorldConstructor(World); // imported directly from cucumber

After hook and getting the scenario results:

After(async function(this: World, scenario: HookScenarioResult) {
    console.log(scenario.result);
    console.log(this.testFunction);
});

kkuriata avatar Jul 02 '20 11:07 kkuriata

Hi, I'm totally new to cypress and js, and trying to move our old cucumber-selenium(ruby) project to cypress-cucumber.

I'm looking for a way to get each scenario's tag and pass them as a variable, but I don't know how and where to call this file \lib\createTestsFromFeature.js

I tried to use it under step definition, but cypress throws out error

in "lib/createTestsFromFeature.js:7:41" ==> const featureTags = testState.feature.tags; Cannot read property 'tags' of undefined

I copied whole /lib folder to my project, I'm totally lost, can anyone help? thanks very very much!!

edmodo-CeciliaChen avatar Jan 21 '21 07:01 edmodo-CeciliaChen

Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I'm very excited about. Furthermore, I'd like to thank @lgandecki ++ for all the work that they've done so far.

Read more about the transfer of ownership here.

The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.

badeball avatar Apr 10 '22 16:04 badeball