What is cypress-mochawesome-reporter?
The cypress-mochawesome-reporter is an npm package that integrates Mochawesome reporting with Cypress, allowing you to generate detailed, visually appealing test reports for your Cypress tests.
What are cypress-mochawesome-reporter's main functionalities?
Generate HTML Reports
This feature allows you to generate HTML reports for your Cypress tests. By including the plugin in your Cypress configuration, you can produce detailed and visually appealing reports.
module.exports = (on, config) => {
require('cypress-mochawesome-reporter/plugin')(on);
};
Customizable Report Options
This feature allows you to customize various options for your reports, such as the directory where reports are saved, whether to overwrite existing reports, and whether to generate HTML and JSON reports.
{
"reporter": "cypress-mochawesome-reporter",
"reporterOptions": {
"reportDir": "cypress/reports",
"overwrite": false,
"html": true,
"json": true
}
}
Screenshots and Videos Integration
This feature allows you to integrate screenshots and videos into your reports. You can add custom logic to handle screenshots and videos, making your reports more comprehensive and useful for debugging.
module.exports = (on, config) => {
require('cypress-mochawesome-reporter/plugin')(on);
on('after:screenshot', (details) => {
// Custom logic for handling screenshots
});
};
Other packages similar to cypress-mochawesome-reporter
mochawesome
Mochawesome is a standalone reporter for Mocha tests that generates a visually appealing HTML report. It is similar to cypress-mochawesome-reporter but is not specifically designed for Cypress. It can be used with any Mocha-based testing framework.
cypress-multi-reporters
Cypress-multi-reporters allows you to use multiple reporters for your Cypress tests. It can be used to combine different reporting formats, such as JSON and HTML, into a single test run. While it does not provide the same level of visual detail as cypress-mochawesome-reporter, it offers flexibility in combining different reporting tools.
cypress-junit-reporter
Cypress-junit-reporter is a reporter that generates JUnit XML reports for Cypress tests. It is useful for integrating Cypress test results with CI/CD pipelines that require JUnit format. Unlike cypress-mochawesome-reporter, it focuses on XML output rather than HTML.
cypress-mochawesome-reporter
![npm](https://img.shields.io/npm/dm/cypress-mochawesome-reporter)
Zero config Mochawesome reporter for Cypress with screenshots attached to tests.
Example report
Cypress compatibility
reporter version | cypress version | reporter branch |
---|
v3 | node >= 14 >= 6.7.0 >= 6.2.0 with experimentalRunEvents: true | master |
v2 | >= 6.7.0 >= 6.2.0 with experimentalRunEvents: true | v2 |
v1 | >= 4.0.0 | v1 |
migration guide from v1
to v2
Setup
This setup tutorial works with Cypress >= v10, looking for older version setup? here
-
install cypress-mochawesome-reporter
npm i --save-dev cypress-mochawesome-reporter
or
yarn add -D cypress-mochawesome-reporter
-
Change cypress reporter & setup hooks
Edit config file (cypress.config.js
by default)
const { defineConfig } = require('cypress');
module.exports = defineConfig({
reporter: 'cypress-mochawesome-reporter',
e2e: {
setupNodeEvents(on, config) {
require('cypress-mochawesome-reporter/plugin')(on);
},
},
});
If you are override before:run
or after:run
hooks, use this:
const { defineConfig } = require('cypress');
const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib');
module.exports = defineConfig({
reporter: 'cypress-mochawesome-reporter',
e2e: {
setupNodeEvents(on, config) {
on('before:run', async (details) => {
console.log('override before:run');
await beforeRunHook(details);
});
on('after:run', async () => {
console.log('override after:run');
await afterRunHook();
});
},
},
});
-
Add to cypress/support/e2e.js
import 'cypress-mochawesome-reporter/register';
-
run cypress
Custom options
If you want to customize your HTML report with mochawesome-report-generator flags just add the flags you want to reporterOptions
const { defineConfig } = require('cypress');
module.exports = defineConfig({
reporter: 'cypress-mochawesome-reporter',
reporterOptions: {
charts: true,
reportPageTitle: 'custom-title',
embeddedScreenshots: true,
inlineAssets: true,
saveAllAttempts: false,
},
e2e: {
setupNodeEvents(on, config) {
require('cypress-mochawesome-reporter/plugin')(on);
},
},
});
Additional reporter options:
name | type | default | description |
---|
embeddedScreenshots | boolean | false | Embedded external screenshots into HTML using base64, use with inlineAssets option to produce a single HTML file |
quiet | boolean | false | Silence console messages |
saveAllAttempts | boolean | true | Save screenshots of all test attempts, set to false to save only the last attempt |
debug | boolean | false | Creates log file with debug data |
Examples
- Simple use of
cypress-mochawesome-reporter
- Using
cypress-multi-reporters
- With
mochawesome-report-generator
flags - Change default screenshots folder in
cypress.json
Run npm i
in root directory then:
cd examples/<example-project>
npm i
npm test