protractormigrationcucumbercypresscypress-cucumber-preprocessor

How to capture scenario result in cypress-cucumber-preprocessor?


I am Migrating Protractor Cucumber framework to Cypress using cypress-cucumber-preprocessor I need to capture Scenario run result -pass or fail value also the scenario name

Earlier with cucumber,the result were available in the after hooks and I was using scenario.result.status to store the result refer below code

After(async function (scenario){
  let name: string = scenario.pickle.name;
  result = scenario.result.status;
});

I found "window.testState.currentScenario" in the web,but where does window come from ? I am getting error Cannot find name window. Reference https://github.com/badeball/cypress-cucumber-preprocessor/issues/285 Not finding similar implementation with cypress-cucumber-preprocessor, Is there any Solution to this?

Another solution given in the issue-285 was by @amitguptagwl was to add the code Cypress.env('currentScenario', scenario) to lib/createTestFromScenario.js in runTest() to get the current scenario detail But how to access result after this step?


Solution

  • After a lot of debugging on web, I found resolution for the problem statement,Sharing my code snippet here

    afterEach(function() {
     const name = Cypress.currentTest.title
     cy.log(name)
     const sceanrioStatus=(Cypress as any).mocha.getRunner().suite.ctx.currentTest.state
     cy.log(sceanrioStatus)
    });
    

    Here Cypress.currentTest.title will fetch the scenario name and (Cypress as any).mocha .. state will fetch the scenario pass or fail result at run time (So Need not have to fetch this from JSON Report) This function will capture result after each scenario/test case run