Integrating Cypress Test Results with PractiTest

If you’re working with Cypress, you can effortlessly integrate your test automation efforts with PractiTest test management platform. One way you can integrate Cypress and PractiTest is through API. Another way to do it is by using PractiTest’s FireCracker tool, which allows upload the XML report generated by Cypress to PractiTest, enabling you to efficiently manage and track your test automation results

Executing a Test Case with Cypress

Below is an example code snippet of a test o execute in Cypress:

// <reference types="cypress">
    it('demo pt test', () => {
      cy.once('uncaught:exception', () => false);
      cy.visit('https://practitest.com')
      cy.get('.nav-button > .vertical-center').click()
      cy.get('.menu__dropdown > :nth-child(1) > :nth-child(8)').click()
      cy.wait(2000)
      cy.get('//*[@id="gsc-i-id1"]').type('welcome to practitest');
    })

Create an XML Report with Cypress

Cypress provides the ability to generate JUnit-XML reports containing detailed test results, which can be integrated seamlessly into your continuous integration (CI) pipelines.

Installation

To get started, install the cypress-junit-reporter plugin:

npm install cypress-junit-reporter --save-dev
Configuration

After installing the plugin, you need to configure Cypress to generate JUnit-XML reports. This can be done in your Cypress configuration file:

const { defineConfig } = require("cypress");
module.exports = defineConfig({
  reporter: "junit",
  reporterOptions: {
    mochaFile: "results/my-test-output.xml",
    toConsole: true,
  },
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
    },
  },
});

Once configured, run your Cypress tests as usual. After the test execution completes, it will generate JUnit-XML reports in the specified output directory.

Example XML Output
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Demo Tests" time="1.959" tests="3" failures="0">
  <testsuite name="Root Suite" timestamp="2024-04-16T07:27:31" tests="0" file="cypress\e2e\2-advanced-examples\PractiTest.cy.js" time="5.000" failures="0">
  </testsuite>
  <testsuite name="Window" timestamp="2024-04-16T07:27:31" tests="3" time="1.954" failures="0">
    <testcase name="Window cy.window() - get the global window object" time="0.417" classname="cy.window() - get the global window object">
    </testcase>
    <testcase name="Window cy.document() - get the document object" time="0.137" classname="cy.document() - get the document object">
    </testcase>
    <testcase name="Window cy.title() - get the title" time="0.136" classname="cy.title() - get the title">
    </testcase>
  </testsuite>
</testsuites>

Uploading Cypress Test Results to PractiTest

Once you have generated the JUnit-XML report from Cypress, you can easily upload the test results to PractiTest using the FireCracker tool. FireCracker allows you to import XML files, including JUnit and NUnit formats, and automatically report the results to PractiTest.

To learn how to work with FireCracker, please refer to the FireCracker help page or watch the following tutorial video: