...
Download the required
npm
packages.Code Block npm install cypress-mochawesome-reporter junit-report-merger mocha-junit-reporter cypress-multi-reporters mocha
Configure Reporters in the
cypress.json
fileNavigate to Project Root Folder > open
cypress.json
Copy and paste the below code.
Code Block language json "reporter": "cypress-multi-reporters", "reporterOptions": { "reporterEnabled": "cypress-mochawesome-reporter, mocha-junit-reporter", "cypressMochawesomeReporterReporterOptions": { "reportDir": "cypress/reports", "charts": true, "reportPageTitle": "My Test Suite", "embeddedScreenshots": true, "inlineAssets": true }, "mochaJunitReporterReporterOptions": { "mochaFile": "cypress/reports/junit/results-[hash].xml" } }, "video": false
Configure
plugin/index.js
fileFrom your Project Root folder > open
cypress
folder > openplugin
folder > openindex.js
fileCopy and paste the below code.
Code Block language jsonjs //index.js inside plugin folder const { beforeRunHook, afterRunHook } = require('cypress-mochawesome-reporter/lib'); const exec = require('child_process').execSync; module.exports = (on) => { on('before:run', async (details) => { console.log('override before:run'); await beforeRunHook(details); //If you are using other than Windows remove below two lines await exec("IF EXIST cypress\\screenshots rmdir /Q /S cypress\\screenshots") await exec("IF EXIST cypress\\reports rmdir /Q /S cypress\\reports") }); on('after:run', async () => { console.log('override after:run'); //if you are using other than Windows remove below line starts with await exec await exec("npx jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit/*.xml"); await afterRunHook(); }); };
Add an entry into support/index.js
From your Project Root folder > Navigate to
cypress
folder > opensupport
folder > openindex.js
fileAdd the below code snippet into
index.js
Code Block language jsonjs //index.js inside support folder import 'cypress-mochawesome-reporter/register';
Run your test
Run your test with
npx cypress run
commandThis will execute all the sample files and will generate the test results inside
Project Root Folder/cypress/reports/junit
folder.The Complete generated HTML file is located in the
Project Root folder/cypress/reports/index.html
location. Openindex.html
in chrome or any other browser to view it.JUnit XML file will be merged into a single file and the merged JUnit file is located in the below location with the name
Project Root folder/cypress/reports/junitreport.xml
.
...