Cypress via JUnit File

Cypress, an end-to-end JavaScript-based framework, is built on Mocha, which supports a number of reporting formats.

AIO Tests supports importing Cypress results in 2 ways

  1. AIO Tests Cypress Reporter- An NPM package plugin for Cypress. As a cypress plugin, it can be configured to report results to AIO Tests directly from cypress.

  2. Via JUnit Reports- Cypress has added native support for the commonly used Mocha reporters, one of them being JUnit. The JUnit XML file can then be imported into AIO Tests, to report results from Cypress runs to AIO Tests.

    This document provides an overview of how you can generate the Junit report from Cypress runs and upload it to AIO Tests.

In this documentation, you’ll understand:

Required Cypress Setup

  1. Node.js 12 or 14 and above

  2. cd /your/project/path

  3. npm init

  4. npm install cypress --save-dev

Mapping Cases with AIO Tests

The below is just a sample test file which opens the Jira cloud URL and logs in with simple assertions.

AIO Tests supports creating tests using Junit reports as well as mapping existing cases.

Mapping Existing AIO Tests to Automated Cypress Tests

AIO Tests generates a unique key for each test created in AIO Test, for example, SCRUM-TC-1. To map an automated case to an existing AIO Test, the it() can take the test case key generated in its description. e.g.it('AT-TC-299 : Login to jira', () => {....}

In the example below, two existing AIO Tests have been mapped to two different cypress tests.

This would pull AT-TC-299 and AT-TC-300 in the execution cycle and mark the result of each of these tests i.e.

“Login to Jira” against AT-TC-299

“Forgot password flow” against AT-TC-300

// jira_navigation.js created with Cypress // // If you're unfamiliar with how Cypress works, // check out the link below and learn how to write your first test: // https://on.cypress.io/writing-first-test describe('Navigation', () => { it('AT-TC-299 : Login to jira', () => { cy.visit("https://yourcompany.atlassian.net") cy.contains('Continue') cy.get('#username').type('youremail@email.com') cy.get('#login-submit').click() cy.get('#password').type('<yourpassword>') cy.get('#login-submit').click() expect(true).to.equal(false) }) it('AT-TC-300 :Forgot password flow', () => { cy.visit("https://yourcompany.atlassian.net") cy.contains('Continue') cy.get('#resetPassword').click() expect(true).to.equal(true) }) it('Cancel Forgot password flow', () => { cy.visit("https://yourcompany.atlassian.net") cy.contains('Continue') cy.get('#resetPassword').click() expect(true).to.equal(true) cy.get('#cancel').click() }) })

Creating new cases in AIO Tests from automated Cypress Tests

If no new key is specified in the spec, then new cases can be created using the results of the tests.

While importing results, if the Create New Case selection is true, then AIO Tests will use the classname.methodname e.g. in the above case, from the Junit results file as a unique automation key to identify the test to AIO Tests.

AIO Tests key would still be generated of the format SCRUM-TC-xyz, which can then be added to the it() name. This would ensure that changes to the description do not end up creating cases where new cases were not intended.

Configuration and Running with Junit Reporter using CLI

Since Cypress has added native support for JUnit, no new dependencies need to be added to generate the JUnit report. However, the report options can be customized in the cypress.json file as below:

"reporterOptions": { "mochaFile": "results/test-output-[hash].xml", }

If you need multiple reporters, then the mocha JUnit reporter needs to be separately installed. More details can be found @ Cypress Multiple Reporters.

Now, we can run the above sample file with the following command. Please note, that the reporter needs to be specified as Junit.

cypress run --reporter junit --spec "cypress/integration/jira_navigation.js"

Sample Report File

The spec file runs and generates a test-output file under the results folder. A sample JUnit results file looks like below:

Importing Results

Post execution of a JUnit suite, the TEST-<xxx>.xml file can be uploaded either via

Please follow the above links to continue to import results using either of the options.

Importing the above file will mark AT-TC-299 and AT-TC-300 as Passed in the cycle.

A new case would be created with the title Navigation Cancel Forgot password flow and added to the cycle with a result of Failed.

 

For further queries and suggestions, feel free to reach out to our customer support via help@aiotests.com.