This package helps to create a new Test Run in Test Rail with results from Cypress Run.
['1', '2', '3']
, your Cypress autotests have these IDs in results = ['1', '2', '3', '4']
=> error! because Test Rail doesn't contain Test Case with ID = 4
.
- Installation
- Add package into
cypress.config.js
file - Update titles for autotests using template
- Running code
- Your own parser and titles for autotests
- Your own name for Test Rail Test Runs
- Using created Test Run for results
- Example
npm i cypress-testrail-integration
- Create any file with Test Rail credentials and data. Example (
.env
file):
TESTRAIL_USERNAME=your_testrail_username
TESTRAIL_PASSWORD=your_testrail_password
TESTRAIL_HOSTNAME=https://your_domain.testrail.io/
TESTRAIL_PROJECT_ID=your_testrail_project_id
- Export package and create a new object into the
after-run-api
part of the cypress config file (use credentials and data for Test Rail from step 1). - Run
addResultsToTestRailTestRun
method for creating a new Test Run in Test Rail (with Test Case IDs from autotests) and adding results into created Test Run.
Full code:
const { defineConfig } = require('cypress');
require('dotenv').config();
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
on('after:run', async (results) => {
// Export package
const TestrailIntegration = require('cypress-testrail-integration');
// Create a new object with Test Rail credentials and data
const testrailIntegration = new TestrailIntegration(
process.env.TESTRAIL_USERNAME, // Test Rail username
process.env.TESTRAIL_PASSWORD, // Test Rail password
process.env.TESTRAIL_HOSTNAME, // Test Rail hostname
process.env.TESTRAIL_PROJECT_ID, // Test Rail project_id
);
// Create a new Test Run in Test Rail and add results from Cypress Run
await testrailIntegration.addResultsToTestRailTestRun(results);
});
return config;
},
specPattern: 'cypress/e2e/**/*.spec.{js, jsx, ts, tsx}',
},
});
Update titles for your autotests using this template:
it('[Test Case IDs with any first letter]: [Autotest\'s title]', () => {
// autotest
});
Example:
it('C1, C2: Verify that google page has input field', () => {
// autotest
});
it('C3: Verify that google page doesn\'t have input field ', () => {
// autotest
});
If you completed to updated autotests titles and config file, run this command for test:
npx cypress run
If all works OK, you will see a new Test Run with results. It contains all Test Cases with Test Case IDs from your autotests.
Video example:
2023-01-03.12-36-21.mp4
If you want to use your own parser and titles for autotests, you can add a new parser into the constructor for TestrailIntegration
.
- Create a new parser for the
cypress.config.js
file - Add it into the
TestrailIntegration
constructor as aparser
param - Update your autotests titles using your own parser
Example:
setupNodeEvents(on, config) {
on('after:run', async (results) => {
function newParser(title) { // new parser
const splittedTitle = title.split(':');
const testCaseIds = splittedTitle[0]
.split(',')
.map((element) => element = element.trim().substring(1));
return testCaseIds;
}
const TestrailIntegration = require('cypress-testrail-integration');
const testrailIntegration = new TestrailIntegration(
process.env.TESTRAIL_USERNAME,
process.env.TESTRAIL_PASSWORD,
process.env.TESTRAIL_HOSTNAME,
process.env.TESTRAIL_PROJECT_ID,
parser = newParser // adding a new parser
);
await testrailIntegration.addResultsToTestRailTestRun(results);
});
return config;
},
['1', '2', '3', '4', '5', '6', '7']
or ['1']
for 1 Test Case ID.
Default name is [Today's date] Test Run: Cypress Autotest
, e.g. 2023-01-03 Test Run: Cypress Autotest
.
If you want to add a new name for Test Rail Test Run, add it into the constructor. Example:
setupNodeEvents(on, config) {
on('after:run', async (results) => {
const TestrailIntegration = require('cypress-testrail-integration');
const testrailIntegration = new TestrailIntegration(
process.env.TESTRAIL_USERNAME,
process.env.TESTRAIL_PASSWORD,
process.env.TESTRAIL_HOSTNAME,
process.env.TESTRAIL_PROJECT_ID,
testRunName = 'New Test Run' // adding a new name for Test Run
);
await testrailIntegration.addResultsToTestRailTestRun(results);
});
return config;
},
If you want to use created Test Run in Test Rail for adding results, you can add it's ID into the addResultsToTestRailTestRun
method. Example:
setupNodeEvents(on, config) {
on('after:run', async (results) => {
const TestrailIntegration = require('cypress-testrail-integration');
const testrailIntegration = new TestrailIntegration(
process.env.TESTRAIL_USERNAME,
process.env.TESTRAIL_PASSWORD,
process.env.TESTRAIL_HOSTNAME,
process.env.TESTRAIL_PROJECT_ID
);
// 25 is ID for existed Test Rail Test Run
await testrailIntegration.addResultsToTestRailTestRun(results, runId = 25);
});
return config;
},
You can use this example: https://github.com/Smoliarick/cypress-testrail-integration-example. This project was set up using cypress-testrail-integration package.