Cypress is bundled with Mocha. So, any reports that can be generated for Mocha, can also be utilized with Cypress. In addition to that Cypress has other third-party reporters like JUnit and TeamCity.
Mochawesome Report
The Mochawesome report is one of the most important reports in Cypress.
- To install mochawesome, run the command given herewith −
npm install mochawesome --save-dev
The following screen will appear on your computer −
- To install mocha, run the command mentioned below −
npm install mocha --save-dev
The following screen will appear on your computer −
- To merge mochawesome json reports, run the following command −
npm install mochawesome-merge --save-dev
The following screen will appear on your computer −
All these packages after installation should get reflected on the package.json file.
To merge multiple reports in a single report, run the following command −
npm run combine-reports
Configurations in cypress.json file
In the cypress.json file, we can set the following configurations for the much awesome reports −
- overwrite − If its value is set to false, there should not be any overwriting from the prior generated reports.
- reportDir − It is the location, where reports are to be saved.
- quiet − If its value is set to true, there should not be any Cypress related output. Only the mochawesome output has to be printed.
- html − If its value is set to false, there should not be any generation of html reports after execution.
- json − If its value is set to true, a json file with execution details will be generated.
Implementation in cypress.json
The implementation for many awesome reports in cypress.json is as follows −
{
"reporter": "mochawesome",
"reporterOptions": {
"reportDir": "cypress/results",
"overwrite": false,
"html": false,
"json": true
}
}
To generate a report for all specs in the integration folder of the Cypress project, run the command given below −
npx cypress run
For running a particular test, run the following command −
npx cypress run --spec "<path of spec file>"
After the execution is completed, the much awesome-report folder gets generated within the Cypress project containing reports in Html and JSON formats.
Right-click on the mochawesome.html report. Then, select the Copy Path option and open the path copied on the browser.
The much awesome report gets opened with details of the execution results, duration, test case name, test steps, and so on.
On clicking on the icon (highlighted in the above image) on the left upper corner of the screen, more options are displayed.
We can get the different views to select the passed, failed, pending, skipped test cases, and the hooks applied to the test.
JUnit Report
Cypress provides one more type of report known as the JUnit report.
To install the package for the JUnit report, run the command stated below −
npm install cypress-junit-reporter --save-dev
The following screen will appear on your computer −
Implementation in cypress.json
Given below is an implementation of the JUnit report in cypress.json −
{
"reporter": "junit",
"reporterOptions": {
"mochaFile": "cypress/results/results.xml",
"toConsole": true
}
}
If we run multiple tests in a run and wish to have a unique report for the individual spec files, we have to add [hash] in the mochaFile parameter in cypress.json.
Implementation to avoid overriding report
Following is an implementation in cypress.json to avoid an overriding report in Cypress −
{
"reporter": "junit",
"reporterOptions": {
"mochaFile": "cypress/results/results-[hash].xml",
"toConsole": true
}
}
To generate a report for all specs in the integration folder of the Cypress project, run the following command −
npx cypress run --reporter junit
The following screen will appear on your computer −
After execution is completed, the results folder gets generated within the Cypress project containing reports in XML format.
teamcity Report
Cypress provides one more type of report known as the TeamCity report.
To install the package for the TeamCity report, run the following command −
npm install cypress-teamcity-reporter --save-dev
The following screen will appear on your computer −
To generate a report for all specs in the integration folder of the Cypress project, run the following command −
npx cypress run --reporter teamcity
The following screen will appear on your computer −