DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Reading an HTML File, Parsing It and Converting It to a PDF File With the Pdfbox Library
  • How To Convert HTML to PNG in Java
  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • The Hidden Engineering Cost of XML in Enterprise Development Workflows

Trending

  • Beyond Manual Annotation: Engineering Self-Correcting Pseudo-Labeling Pipelines
  • How SaaS Architectures Break at Scale — and the Engineering Decisions That Prevent It
  • When Snowflake Lies to You: Understanding False Failures in dbt Pipelines
  • Chaos Engineering Has a Blind Spot. Agentic AI Lives in It.
  1. DZone
  2. Coding
  3. Languages
  4. 7 Easy Steps to Generate Both XML and HTML Reports in Cypress

7 Easy Steps to Generate Both XML and HTML Reports in Cypress

This tutorial explains an easy way to generate merged XML and HTML report in cypress Automation Framework.

By 
Ganesh Hegde user avatar
Ganesh Hegde
·
Jun. 28, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
28.8K Views

Join the DZone community and get the full member experience.

Join For Free

The common requirement when we are working with automation tests in we need to generate both XML and HMTL reports. When it comes to Cypress it relies on Mochawesome reporter. In this article, I will explain to you a simple way to generate HTML and Junit XML reporter in your Cypress end-to-end Automation framework. 

If you look over the internet there are many articles but for beginners, it's very complicated Since there is some complexity involved. 

This tutorial also answers the Questions commonly searched on the internet

How to Generate XML and HTML files in Cypress?
How to configure HTML and XML files with cypress?
How to Integrate HTML and XML files with Cypress?
How to Generate and Merge Junit XML file using mocha Junit reporter in Cypress?
How to Configure reports into Cypress End to End Automation framework?
 

This article also talks about merging Junit XML file into a single file

Let’s get started.

Generating both XML and HTML reports with Screenshots and Merging all XML files in Cypress

Assumptions:

Here the assumption is you have already working cypress framework and you are looking for integrating both Junit and HTML reports into your cypress.

Step 1: Download Required npm Packages

We need to download few npm packages

npm install cypress-mochawesome-reporter junit-report-merger mocha-junit-reporter cypress-multi-reporters mocha


cypress-multi-reporters: This package is used for configuring multiple reports in our case Junit reporter and HTML reporter.

mocha-junit-reporter: Mocha Junit Reporter generates Junit XML file for each spec.

junit-report-merger: Since the Mocha Junit Reporter generates a JUnit XML file for each spec we need to merge them all at the end to create a single XML file.

cypress-mochawesome-reporter: This package helps to generate HTML reports.

Step 2: Configure Reporters in cypress.json File

Navigate to Project Root Folder > open cypress.json

Copy and paste the below code.

cypress.json file

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


Screenshot:

Configure Reporters in cypress.json File

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

JavaScript
 
//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 (having await exec)
    await exec("npx jrm ./cypress/reports/junitreport.xml ./cypress/reports/junit/*.xml");
    await afterRunHook();
  });
};


Screenshot:

Configure plugin/index.js File


Step 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 below code snippet into index.js

JavaScript
 
//index.js inside support folder
import 'cypress-mochawesome-reporter/register';



Add an Entry Into support/index.js


Step 5: Run Your Test

Run your test with either npx cypress run command.

Or, If you are already having the package.json script command use it to run your specs.

Step 6: Viewing HTML File

The Complete generated HTML file is located in the below location

Project Root folder > cypress > reports > index.html

Viewing HTML File

You can use this XML file when you integrate with CI/CD either Jenkins, Azure DevOps, or any other tools.

Hope you enjoyed this…

Encourage me to write more articles and help the community.

 

If you are looking for any help, support, guidance contact me on LinkedIn|https://www.linkedin.com/in/ganeshsirsi/.

XML HTML

Opinions expressed by DZone contributors are their own.

Related

  • Reading an HTML File, Parsing It and Converting It to a PDF File With the Pdfbox Library
  • How To Convert HTML to PNG in Java
  • Stop Poisoning Your Models: How I Built a CV Dataset Quality Toolkit I Can Reuse Forever
  • The Hidden Engineering Cost of XML in Enterprise Development Workflows

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook