0.1.5 • Published 1 year ago

cypress-testrail-paper v0.1.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Build Status NPM Downloads GitHub release (latest by date) NPM License

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!

1. Installation

npm i cypress-testrail --save-dev

2. Setup Wizard

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,
    "includeAllFailedScreenshots": true,
    "includeAllCasesDuringCreation": true
  }
}

3. Execution Modes

The integration has 2 different modes, that you can select while running our Setup CLI command.

3.1 Mode A: Send result to specific Run in TestRail

With this mode, all results are fired against an existing Test Run 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.

3.2 Mode B: Create new Run in TestRail for every Cypress run

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.

4. Register Plugin

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)
    }
,
}

5. Map Test Cases

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!

6. Advanced Features

6.1 Sending Screenshots on failures

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.

{
  "testrail": {
      // ....
      "screenshots": true
  }
}

7. Variables

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.

ENVJSONRequiredDescription
CYPRESS_TESTRAIL_DOMAINtestrail.domainyesTestRail domain
CYPRESS_TESTRAIL_USERNAMEtestrail.usernameyesTestRail username
CYPRESS_TESTRAIL_PASSWORDtestrail.passwordyesTestRail password
CYPRESS_TESTRAIL_SCREENSHOTStestrail.screenshotsnoSend screenshots for failed tests. Values: true\
CYPRESS_TESTRAIL_INCLUDE_ALLtestrail.includeAllCasesDuringCreationnoInclude all test cases in test run creation.Values: true \ falseDefault: false
CYPRESS_TESTRAIL_INCLUDE_ALL_SCREENSHOTStestrail.includeAllFailedScreenshotsnoInclude all failed screenshots.Values: true \ falseDefault: false
CYPRESS_TESTRAIL_RUN_IDtestrail.runIdyes (Mode A)TestRail RunID to fire against, e.g. R123
CYPRESS_TESTRAIL_PROJECT_IDtestrail.projectIdyes (Mode B)TestRail ProjectID, e.g. P45
CYPRESS_TESTRAIL_MILESTONE_IDtestrail.milestoneIdyes (Mode A)TestRail MilestoneID, e.g. M4
CYPRESS_TESTRAIL_SUITE_IDtestrail.suiteIdyes/no (Mode B)TestRail SuiteID, e.g. S8.Some projects might require this!
CYPRESS_TESTRAIL_RUN_NAMEtestrail.runNameno (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_CLOSEtestrail.closeRunno (Mode B)Automatically close test runs.Values: true \ falseDefault: false

Use on CLI

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 

Use in cypress.env.json

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": "",
        "closeRun": false,
        "includeAllFailedScreenshots": false,
        "includeAllCasesDuringCreation": false
    }
}

Copying / License

This repository is distributed under the MIT License (MIT).