4

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

2 Answers 2

11

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

5
  • Are you testing on windows? I am getting Error: ." --inline contains invalid WIN32 path characters. when running npx marge cypress/report/output.json --reportDir ./ --inline
    – user14903560
    Jan 7, 2021 at 22:41
  • 2
    Also, subsequent runs are producing duplicate json (same content but '_001' suffix) which will lead to the tests showing twice on the HTML. Perhaps you need a rim-raf step?
    – user14903560
    Jan 7, 2021 at 22:44
  • @AloysiusParker Yes I was running on Windows. And in my end, I was not experiencing duplicate data issue. Can you please recheck the reporter configurations? Also Ensure you have Node version higher than 8 Jan 8, 2021 at 5:48
  • 1
    +1! For merging the reports into a single one, it is better to use -o cypress/report/output.json shell output redirection (> cypress/report/output.json) since shell output redirection will include yarn timing info (if you are using yarn). Mar 23, 2021 at 23:02
  • @MitchellTracy That's a great suggestion! Thank you Mar 25, 2021 at 17:01
1

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

5
  • Thank you, I will try that today and reply back.
    – soccerway
    Dec 3, 2018 at 18:29
  • Keep in mind that you will have to add to your project dev dependencies mocha and mochawesome. Refer to their documentation for full details
    – Alex Serra
    Dec 4, 2018 at 9:45
  • I have installed npm install --save-dev mochawesome and added the "reporter": "mochawesome" in cypress.json file, but it failed to run in headless mode and can't find the relevant files
    – soccerway
    Dec 4, 2018 at 9:48
  • 1
    Take a look at this question for some additional info. Dec 4, 2018 at 10:08
  • Your will also have to install mocha as a peer dependency of your project in order to run mochawesome. Can you post the errors thrown to you?
    – Alex Serra
    Dec 4, 2018 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.