Search code examples
cucumbercypressreportpackage.json

Cucumber HTML report does not get generated if any test/scenario fail


I'm generating Cucumber html report in Cypress, based on this article Generate Cucumber .html report in Cypress and everything is ok and works perfect, except when one of my test or scenarios fail within the feature file. In those cases, the HTML report does not get generated.

My configuration is exactly how it's mentioned in the link above. Except that I'm executing the report via the package.json when I run the test.

When I run my test in the way below, the report is generated correctly if all tests pass. However, it's not like that if at least one fails. The curious thing is, if I replace && by || the problem is solved, but in this case if all tests pass then it happen the opposite and the report does not get generated.

The thing is that currently I haven't found a way how to generate the report no matter if all tests pass, fail or some fails and some don't.

    "scripts": {
        "cy:test": "npm run cy:run && npm run cucumber-report",
        "cy:run": "cypress run --env TAGS=\"not @skip\" --browser chrome --headed",
        "cucumber-report": "node cucumber-html-report.js"
    }

Solution

  • Try using a single & to run 2nd part regardless of exit code

    See How-to: Conditional Execution

    "scripts": {
      "cy:test": "npm run cy:run & npm run cucumber-report",
      "cy:run": "cypress run --env TAGS=\"not @skip\" --browser chrome --headed",
      "cucumber-report": "node cucumber-html-report.js"
    }
    

    The pattern ... && ... || ... will also work if you have different post commands depending on exitcode

    "scripts": {
      "cy:test": "npm run cy:run && npm run cucumber-report || npm run failed:test",
      "cy:run": "cypress run --env TAGS=\"not @skip\" --browser chrome --headed",
      "cucumber-report": "node cucumber-html-report.js",
      "failed:test": "..."
    }