- Cypress Tutorial
- Cypress - Home
- Cypress - Introduction
- Cypress - Architecture and Environment Setup
- Cypress - Test Runner
- Cypress - Build First Test
- Cypress - Supported Browsers
- Cypress - Basic Commands
- Cypress - Variables
- Cypress - Aliases
- Cypress - Locators
- Cypress - Assertions
- Cypress - Text Verification
- Cypress - Asynchronous Behavior
- Cypress - Working with XHR
- Cypress - jQuery
- Cypress - Checkbox
- Cypress - Tabs
- Cypress - Dropdown
- Cypress - Alerts
- Cypress - Child Windows
- Cypress - Hidden Elements
- Cypress - Frames
- Cypress - Web Tables
- Cypress - Mouse Actions
- Cypress - Cookies
- Cypress - Get and Post
- Cypress - File Upload
- Cypress - Data Driven Testing
- Cypress - Prompt Pop-up Window
- Cypress - Dashboards
- Cypress - Screenshots and Videos
- Cypress - Debugging
- Cypress - Custom Commands
- Cypress - Fixtures
- Cypress - Environment Variables
- Cypress - Hooks
- Cypress - Configuration of JSON File
- Cypress - Reports
- Cypress - Plugins
- Cypress - GitHub
- Cypress Useful Resources
- Cypress - Quick Guide
- Cypress - Useful Resources
- Cypress - Discussion
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 −
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 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.
Right-click on the mochawesome.html report. Then, select the Copy Path option and open the path copied on the browser.
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.
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 −
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 −
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 −
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 −
To Continue Learning Please Login
Login with Google