soccerway
soccerway

Reputation: 12009

Export the test results to HTML in cypress

Is there any way the test results in Cypress can be exported to an HTML or any other format ( like cucumber-report.html)

Upvotes: 6

Views: 13132

Answers (2)

Steffi Keran Rani J
Steffi Keran Rani J

Reputation: 4113

You can use mochawesome reporter to run to export the report. But the caveat is mochawesome when used alone generates individual reports which get overridden by the latest spec file that is run. In order to merge all the individual mochawesome reports, give a shot to mochawesome-merge which will combine all the test results and export it in HTML.

Towards that end,

  1. Install mocha, mochawesome and mochawesome-merge (mochawesome has peer dependency on mocha)
npm install mocha
npm install mochawesome --save-dev
npm install mochawesome-merge --save-dev
  1. In the cypress.json, paste the following config:
{
      "reporter": "mochawesome",
     "reporterOptions": {
       "charts": true,
       "overwrite": false,
       "html": false,
       "json": true,
       "reportDir": "cypress/report/mochawesome-report"
      }
    }
  1. Run Cypress

npx cypress run --reporter mochawesome

  1. Once all tests are run, merge the reports into a single one

npx mochawesome-merge cypress/report/mochawesome-report/*.json > cypress/report/output.json

  1. Now convert the JSON into HTML

npx marge cypress/report/output.json --reportDir ./ --inline

  1. Once the HTML report is generated, you will see something like this:

✓ Reports saved: E:\Project_Path\cypress\report\output.html

Upvotes: 14

Alex Serra
Alex Serra

Reputation: 141

Yes, you can use any mocha reporter as cypress is build on top of it: https://mochajs.org/#reporters spec reporter is the default one.

You will have to add them to your cypress.json config like this:

{
  "reporter": "mochawesome" 
}

You can find all the information here: Reporters

Upvotes: 1

Related Questions