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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

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
  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing

Trending

  • Integration Isn’t a Task — It’s an Architectural Discipline
  • Understanding IEEE 802.11(Wi-Fi) Encryption and Authentication: Write Your Own Custom Packet Sniffer
  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  • Mastering Advanced Aggregations in Spark SQL
  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
DZone Core CORE ·
Jun. 28, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
28.1K 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
  • How to Convert XLS to XLSX in Java
  • Thread-Safety Pitfalls in XML Processing

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!