Cypress Integration

Cypress framework is a JavaScript-based end-to-end testing framework built on top of Mocha, which allows you to write end to end, integration as well as unit tests. Now, AIO Tests supports direct reporting from Cypress, with it’s cypress-aiotests-reporter npm package.

 

What does the AIO Tests native Cypress reporter do?

With AIO Test’s Cypress reporter, AIO Tests simplifies reporting of results from the automated Cypress tests to AIO Tests for Jira. By hooking into Cypress events, the AIO Tests Reporter reports results in the after:spec event, after every spec run finishes. The reporter can

  • report results against AIO Tests cases

  • create a new cycle for the executions or reuse existing cycles, based on the configuration done in cyress.json

  • upload attachments for failed executions

  • Retries can either be reported as new runs or used to update the existing run

Please note that the reporter can work only with cypress run and not with cypress open command, since Cypress app doesn’t provide the results information in the after:spec event.

How to get started?

AIO Tests Cypress reporter comes as an npm package and can be installed via the standard install command.

npm install cypress-aiotests-reporter

How to report results?

AIO Tests reporter reports results after every spec file. Once the tests in a spec file are finished, the reporter searches for mappings in the tests and uploads mapped test case results to AIO Tests.

The below section covers how to map Cypress automated cases to AIO Tests, how to setup the AIO Tests Reporter and the possible configuration values.

Mapping automated Cypress tests to AIO Tests

The AIO Tests Case key can be added to the ` describe ` and ` it ` function descriptions. <br> If there are multiple case keys in a single description, then the result of one test will be updated to multiple cases.

**Please note that the case key can appear anywhere in the description**

  1. Mapping single case

1 2 3 4 5 6 7 8 describe('example to-do app', () => { beforeEach(() => { .. }) it('displays two todo items by default (NVTES-TC-72)', () => { cy.get('.todo-list li').should('have.length', 2) cy.get('.todo-list li').first().should('have.text', 'Pay electric bill') cy.get('.todo-list li').last().should('have.text', 'Walk the dog') })

2. Mapping to multiple cases

1 2 3 4 5 6 7 8 9 describe('example to-do app', () => { beforeEach(() => { .. }) it('NVTES-TC-72, NVTES-TC-73 : displays two todo items by default', () => { cy.get('.todo-list li').should('have.length', 2) cy.get('.todo-list li').first().should('have.text', 'Pay electric bill') cy.get('.todo-list li').last().should('have.text', 'Walk the dog') })

Mapping automated Cypress Cucumber tests to AIO Tests

The AIO Tests Case key can be added to the scenario name. If there are multiple case keys in a single scenario, then the result of one scenario will be updated to multiple AIO Tests cases.

**Please note that the case key can appear anywhere in the scenario name**

  1. Mapping single case - scenario is mapped to NVTES-TC-1003 in below case

1 2 3 4 Feature: Settings Tests Scenario: NVTES-TC-1003 visiting the frontpage When I visit Settings page Then I see all configurable options

2. Mapping to multiple cases

1 2 3 4 5 6 Feature: Settings Tests Scenario: NVTES-TC-1003, NVTES-TC-1007 Validate settings and API keys When I visit Settings page Then I see all configurable options When I click on API Keys Then I see option to generate an API key

3. Scenario Outline with Examples

1 2 3 4 5 6 7 8 9 10 Feature: Settings Tests Scenario Outline: {TCId} Validate links work When I visit Settings page Then I see all configurable options When I click on {PageToTest} Then Profile {PageToTest} page opens with options Examples: |TCId |PageToTest | |NV-TC-11 |API Token | |NV-TC-12 |Email Settings |

Setup & Configuration

  1. Versions before Cypress 10 Register the plugin to the Cypress plugins file as below:

1 2 3 4 5 6 // cypress/plugins/index.js const { registerAIOTestsPlugin } = require('cypress-aiotests-reporter/src') module.exports = (on, config) => { registerAIOTestsPlugin(on,config); }

2. Cypress 10 and beyond In Cypress 10, the pluginsFile option was removed. This option was replaced with the new setupNodeEvents(). So, the plugin registration has to happen as below in the cypress.config.js

1 2 3 4 5 6 7 8 9 10 11 12 // cypress.config.js const { defineConfig } = require("cypress"); const { registerAIOTestsPlugin } = require('cypress-aiotests-reporter/src') module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { registerAIOTestsPlugin(on,config); // implement node event listeners here }, }, }

Configure

The AIO Tests Reporter config needs to be set in the env property of cypress.json. Or it can be programmatically modified in your plugins/index.js

Depending on the Jira hosting, the authentication information needs to be provided as below.

Cloud

For Jira Cloud (eg. https://yourco.atlassian.net/..), the "cloud" property needs to be set in the env.aioTests config for authentication.

  1. Local runs : The API Key generated from AIO Tests, needs to be set as "apiKey" value.

  2. CI/CD: For CI runs, you can set the AIO_API_KEY environment variable to pass it externally as a SECRET.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // cypress.json { "env": { "aioTests": { "enableReporting": true, "cloud": { "apiKey": "<your API KEY>" }, "jiraProjectId": "SCRUM", "cycleDetails": { "createNewCycle": true, "cycleName": "Cypress first run from plugin", "cycleKey": "NVTES-CY-2" }, "addNewRun": true, "addAttachmentToFailedCases": true, "createNewRunForRetries": true } } }

Server

For Jira Hosted or DataCenter versions, the "hosted" property needs to be set in the env.aioTests for authentication.
The "jiraUrl" needs to be specified with the base url of the hosted Jira instance.

Authentication is supported either by providing Jira username and password or by using the Jira PAT. More information can be found on Server Authentication here

  1. Local runs : For local runs, either "jiraUsername" + "jiraPassword" can be set or one can simply set the "jiraPAT" value.

  2. CI/CD: For CI runs, you can set the JIRA_USERNAME and JIRA_PASSWORD or JIRA_PATenvironment variable to pass it externally as a SECRET.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 // cypress.json { "env": { "aioTests": { "enableReporting": true, "hosted" : { "jiraUrl": "https://jira.yourco.com", "jiraPAT": "PAT from Jira Tokens | JIRA_PAT as environment variable", "jiraUsername": "Jira Username. If PAT is specified, then username is not required", "jiraPassword": "Jira password, required if authentication is through username/password" }, "jiraProjectId": "SERV", "cycleDetails": { "createNewCycle": true, "cycleName": "Cypress Nightly Run ", "cycleKey": "SERV-CY-2" }, "addNewRun": true, "addAttachmentToFailedCases": false, "createNewRunForRetries": false } } }

Cypress 10 and above

For Cypress 10, the settings have moved to the cypress.config.js. Set the above aioTests configuration in the cypress.config.js as below:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 module.exports = defineConfig({ env: { "aioTests": { "enableReporting": true, "cloud": { //Replace with server authentication if using Jira Server "apiKey": "apikey for cloud" }, "jiraProjectId": "NVTES", "cycleDetails": { "createNewCycle": true, "cycleName": "Cypress first run from plugin", "cycleKey": "NVTES-CY-2" }, "addNewRun": true, "addAttachmentToFailedCases": true, "createNewRunForRetries": true }, }, e2e: {... }}

 

Configurable values

Value

Description

Value

Description

enableReporting

Set to true to make the current run update results to AIO Tests. Default false.

jiraProjectId

Jira Project key to update results to

cycleDetails.createNewCycle

Set to true to create a new cycle for run being reported

cycleDetails.cycleName

Works if createNewCycle is true, sets the cycle name of cycle getting created

cycleDetails.cycleKey

AIO Tests cycle key that should be updated. Used if createNewCycle is false

addNewRun

Create a new run or update an existing run in the cycle

addAttachmentToFailedCases

Set to true to attach screenshots, if available, for failed cases

createNewRunForRetries

Set to true if each retry should create a new run

Logging

AIO Tests Reporter logs can be seen in the run logs as below for successful updates

Errors received while updating will appear in a similar way

Queries/Suggestions?

For any queries, suggestions or issues, please feel free to reach out @ help@aioreports.com