How to import Cypress automation results into QMetry (QTM)?

This article is intended for users who want to import Cypress automation results into QTM. QMetry supports importing the JUnit automation result files. Cypress can generate the test results file in JUnit format that can be further imported into QMetry (QTM). Using https://www.npmjs.com/package/mocha-junit-reporter package of Cypress the test result files are generated in JUnit/XML format.

You can follow the below steps to generate the result files in JUnit/XML in Cypress.

Note: The steps mentioned below are just for reference purposes. Any inquiries/issues related to these steps are out of QMetry Support scope, you can directly reach out to Cypress support for any queries.

  1. Download the required npm packages.

    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.

      "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.

      //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

  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.

 

The generated JUnit/XML file or zip containing XMLs can be imported to QMetry using the steps to Import Automation Results through REST API.