Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Download the required npm packages.

    Code Block
    npm install cypress-mochawesome-reporter junit-report-merger mocha-junit-reporter cypress-multi-reporters mocha
  2. Configure Reporters in the cypress.json file

    • Navigate to Project Root Folder > open cypress.json

    • Copy and paste the below code.

      Code Block
      languagejson
      "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
  3. Configure plugin/index.js file

    • From your Project Root folder > open cypress folder > open plugin folder > open index.js file

    • Copy and paste the below code.

      Code Block
      languagejsonjs
      //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();  
        });  
      };
  4. Add an entry into support/index.js

    • From your Project Root folder > Navigate to cypress folder > open support folder > open index.js file

    • Add the below code snippet into index.js

      Code Block
      languagejsonjs
      //index.js inside support folder
      
      import 'cypress-mochawesome-reporter/register';
  5. Run your test

    • Run your test with npx cypress run command

    • This 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. Open index.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.

...