Cypress - Reports


Cypress is bundled with Mocha. So, any reports that can be generated for Mocha, can also be utilised 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 −

Install Mochawesome
  • To install mocha, run the command mentioned below −

npm install mocha --save-dev

The following screen will appear on your computer −

Install Mocha
  • To merge mochawesome json reports, run the following command −

npm install mochawesome-merge --save-dev

The following screen will appear on your computer −

Merge Mochawesome JSON Reports

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 mochawesome 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 mochawesome report 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 mochawesome-report folder gets generated within the Cypress project containing reports in html and json formats.

JSON Formats.

Right-click on the mochawesome.html report. Then, select the Copy Path option and open the path copied on the browser.

Mochawesome HTML

The mochawesome 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.

Mochawesome Report

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 JUnit report, run the command stated below −

npm install cypress-junit-reporter --save-dev

The following screen will appear on your computer −

JUnit Report

Implementation in cypress.json

Given below is an implementation of 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 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 −

Cypress Project

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 teamcity report, run the following command −

npm install cypress-teamcity-reporter --save-dev

The following screen will appear on your computer −

Teamcity Report

To generate 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 −

Running
Advertisements