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
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,
- Install
mocha
,mochawesome
andmochawesome-merge
(mochawesome has peer dependency on mocha)
npm install mocha npm install mochawesome --save-dev npm install mochawesome-merge --save-dev
- In the
cypress.json
, paste the following config:
{
"reporter": "mochawesome",
"reporterOptions": {
"charts": true,
"overwrite": false,
"html": false,
"json": true,
"reportDir": "cypress/report/mochawesome-report"
}
}
- Run Cypress
npx cypress run --reporter mochawesome
- Once all tests are run, merge the reports into a single one
npx mochawesome-merge cypress/report/mochawesome-report/*.json > cypress/report/output.json
- Now convert the JSON into HTML
npx marge cypress/report/output.json --reportDir ./ --inline
- Once the HTML report is generated, you will see something like this:
✓ Reports saved: E:\Project_Path\cypress\report\output.html
-
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
– user14903560Jan 7, 2021 at 22:41 -
2Also, 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?– user14903560Jan 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 -
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
-
-
Keep in mind that you will have to add to your project dev dependencies
mocha
andmochawesome
. Refer to their documentation for full details 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 Dec 4, 2018 at 9:48 -
1
-
Your will also have to install
mocha
as a peer dependency of your project in order to runmochawesome
. Can you post the errors thrown to you? Dec 4, 2018 at 16:21