This integration helps you to automatically send test results to TestRail. And yes, super easy and simple!
Add your TestRail credentials in Cypress, decide which test results should be sent to TestRail and you're done!
npm i cypress-testrail --save-dev
Node 13
Note: Versions of Node < Node 13 may work but will require enabling experimental-modules flag.
The integration has a CLI command that you can use to build your configuration in an interactive way.
Run it with this command and enter your data:
./node_modules/.bin/cypress-testrail
Please copy the displayed JSON structure of that command to your cypress.env.json
file.
You can of course also build such a JSON manually. In addition to this, you can also use ENV variables. Please see the section on variables below for more.
Here is a sample of a JSON from the CLI command.
{
"testrail": {
"domain": "my-company.testrail.io",
"username": "myUser",
"password": "myPwd",
"runId": "R123",
"screenshots": true
}
}
The integration has 2 different modes, that you can select while running our Setup CLI command.
With this mode, all results are fired against an existing Test Run or a list of Test Runs in TestRail. This is a good option if you have already prepared your plan in TestRail and just need to have Cypress doing the work for you.
Please keep in mind, that the provided run must not be closed, so that the TestRail API allows you to send results to it.
Results will only be saved, if the sent TestCaseID is existing in that run inside TestRail.
Sometimes you want to create test runs dynamically inside TestRail. For this, just assign the ProjectID and the optional MilestoneID or SuiteId of TestRail in your configuration.
The integration will then start a new run in TestRail and send the results to this one. It is also possible to provide a custom (or dynamically created) name for the new test run.
Just place this line in your plugins/index.js
file.
There's nothing more that is required to register the TestRail reporter.
const TestRailReporter = require('cypress-testrail');
module.exports = (on, config) => {
new TestRailReporter(on, config).register();
return config
}
In addition to this, you can register the reporter with a custom comment. That comment will then be sent to the TestRail result along with the other metadata, such as Cypress version, browser, baseURL and more.
const customComment = 'AUT v' + Cypress.env('MY_APP_VERSION');
new TestRailReporter(on, config, customComment).register();
If you are running Cypress 10 and higher, then there is no classic plugin/index.js file anymore.
You can of course still use it. The new cypress.config.js
has a configuration option called setupNodeEvents
.
That one acts as the perfect entrypoint to either directly start the configuration, or just load a separate file.
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config)
{
return require('./cypress/plugins/index.js')(on, config)
}
,
}
Enable experimentalInteractiveRunEvents
in cypress.config.js
We're almost done.
You can now map TestRail test cases to your Cypress tests.
Please use the TestRail case ID as a prefix inside the Cypress test title.
The plugin will automatically extract it, and send the results to your test run in TestRail.
The Case ID needs to be at the beginning and separated with an :
from the rest of the title.
You can also add multiple Case IDs before the :
. Results will be sent for all found test cases.
it('C123: My Test for TestRail case 123', () => {
cy.get('#sw-field--name').type('John');
// ...
// ...
})
it('C123 C54 C36: My Test for multiple TestRail case IDs', () => {
cy.get('#sw-field--name').type('John');
// ...
// ...
})
That's it!
You can now start Cypress (restart after config changes), and all your results should be sent to TestRail as soon as your mapped tests pass or fail!
You can automatically send the latest failure screenshot of Cypress to TestRail. This is not enabled by default. Just enable it, and it will automatically work. Once enabled, the latest failed screenshot is sent to TestRail.
{
"testrail": {
"screenshots": true
}
}
If you want to send all failed screenshots to TestRail, just enable the additional (optional) feature. This will send all failed screenshots of all attempts in Cypress to TestRail.
{
"testrail": {
"screenshots": true,
"screenshotsAll": true
}
}
This is a list of all available variables and their explanation.
The list shows you the ENV variable name as well as their JSON structure name. You can use all variables in both scopes.
Examples on how to use it are below the list.
ENV | JSON | Required | Description |
---|---|---|---|
CYPRESS_TESTRAIL_DOMAIN | testrail.domain | yes | TestRail domain |
CYPRESS_TESTRAIL_USERNAME | testrail.username | yes | TestRail username |
CYPRESS_TESTRAIL_PASSWORD | testrail.password | yes | TestRail password |
CYPRESS_TESTRAIL_SCREENSHOTS | testrail.screenshots | no | Send last screenshot of failed test. Values: true/false |
CYPRESS_TESTRAIL_SCREENSHOTS_ALL | testrail.screenshotsAll | no | Send all screenshots of failed test. (requires screenshots to be enabled). Values: true/false |
CYPRESS_TESTRAIL_RUN_ID | testrail.runId | yes (Mode A) | TestRail RunID to fire against, e.g. R123 |
CYPRESS_TESTRAIL_RUN_IDS | testrail.runIds | yes (Mode A) | TestRail RunIDs to fire against, e.g. ["R123", "R456"]. Either provide single runID or this list. Send comma separated as ENV variable from CLI (xxx="R1,R2" |
CYPRESS_TESTRAIL_PROJECT_ID | testrail.projectId | yes (Mode B) | TestRail ProjectID, e.g. P45 |
CYPRESS_TESTRAIL_MILESTONE_ID | testrail.milestoneId | yes (Mode A) | TestRail MilestoneID, e.g. M4 |
CYPRESS_TESTRAIL_SUITE_ID | testrail.suiteId | yes/no (Mode B) | TestRail SuiteID, e.g. S8. Some projects might require this! |
CYPRESS_TESTRAIL_RUN_NAME | testrail.runName | no (Mode B) | Template for the names of created runs. You can provide a fixed text but also use dynamic variables. Variables: (__datetime__) => generates e.g. "01/04/2022 12:45:00" |
CYPRESS_TESTRAIL_RUN_INCLUDE_ALL | testrail.runIncludeAll | no | Include all test cases in test run creation. Values: true/false |
CYPRESS_TESTRAIL_RUN_CLOSE | testrail.closeRun | no (Mode B) | Automatically close test runs. Values: true/false |
To provide variables on CLI just expose them before executing your actual command.
CYPRESS_TESTRAIL_PROJECT_ID=2 CYPRESS_TESTRAIL_MILESTONE_ID=15 ./node_modules/.bin/cypress run
You can also provide the variables in a JSON structure like this inside your cypress.env.json file.
{
"testrail": {
"domain": "",
"username": "",
"password": "",
"screenshots": false,
"projectId": "",
"milestoneId": "",
"suiteId": "",
"runName": "",
"runIncludeAll": false,
"closeRun": false,
"screenshots": false
}
}
This repository is distributed under the MIT License (MIT).