1.2.1 • Published 2 years ago

mocha-testrail-reporter-2 v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

mocha-testrail-reporter-2

This library allows to testrail to be integrated to a mocha automation suite as a mocha reporter.

Pre-requisites

  • Requires mochawesome-report-generator to be present on the suite, in which the mochawesome.json file generated will be used to extract testcases to be uploaded to Testrail. ( Extractor tool added to releases. )

  • Using multi-custom-reporter will allow both reporters work together.

Installation

Using NPM:

npm i mocha-testrail-reporter-2

Add reporter to mocha.json

  1. Standalone using mocha-testrail-reporter-2.
{
  ...,
  "reporter": ["mocha-testrail-reporter-2"],
  "reporter-options" : "",
  ...
}
  1. i. Using multi-custom-reporter (Recommended)
{
  ...,
  "reporter": ["mocha-multi-reporters"],
  "reporter-options" : "configFile=config.json",
  ...
}
  1. ii. Add config.json to root directory of your automation suite if using multi-custom-reporter.
{
  "reporterEnabled": "mochawesome, mocha-testrail-reporter-2",
  "mochawesomeReporterOptions": {
      "reportDir": "./artifacts"
  }
}

Note

Do not forget to install mochawesome & mocha-multi-reporters as dependency.

Please read mochawesome & mocha-multi-reporters documentations if anything unclear.

Extracting & uploading testcases to Testrail

On the releases section, there is the "mochawesome extractor tool" attached and has all the steps detailed on how to use the tool.

On testrail, create your project, followed by suite and import testcases using the the "Import using csv" option.

Testrail configuration

Create a 'testrail.json' json file on the root directory of the project with the following:

{
  "host": "https://yourtestrail.domain.here",
  "email": "email@address.here",
  "apikey": "your_testrail_api_key_here",
  "project_name": "Demo Project Name",
  "project_id": 1,
  "suite_id": 1,
  "testrail_enabled": false,
  "mocha": "--optional field", 
  "version": "--optional field" 
}

Configuration options

host: string Domain name of the Testrail domain (e.g. domain.testrail.io)

email: string Username/Email for the testrail account

apikey: string password or API token for user account

project_name: number name of project for which the Testrun will be created

projectId: number project number where the suite has been added

suite_id: number suite number where the tests have been uploaded

testrail_enabled: boolean disable/enable testrail for the automation suite

mocha: string set path for the 'mocha.json' file, used to retrieve the grep value. (default path is root directory of project or ./test/mocha.json)

version: string set path where a version function can be defined to return a version of the Automation suite (default path is root directory of project)

Configuration example for the mocha options

Configure mocha path to be present at config/mocha.json. (Not required if file is present at root directory of project or at ./test/mocha.json)

{
  ...,
  "mocha": "config/mocha.json",
}

Configuration example for the version options

Define version.js path to be present at config/version.js. (Not required if file is present at root directory of project)

{
  ...,
  "version": "config/version.js",
}
  1. Returning a static version
exports.version = async () => {
    return "1.0.0";
}
  1. Returning a dynamic version using a request via superagent. Example using https://reqres.in/api/users/1
let request = require("supertest");

exports.version = async () => {
    try
    {
        return request("https://reqres.in")
          .get("/api/users/1")
          .then(async function (response) {
            return response.body['data']['id'] != undefined ? response.body['data']['id'] : 'undefined';
          });
    }
    catch(err)
    {
        return 'Error in code versioning logic';
    };
};

Testail Execution on CLI & Testrail

image

image

image

Failed tests results on Testrail

image

Testrail Run with mocha defined

image

Testrail Run with version defined

image

Testrail Run with mocha & version defined

image