mocha-testrail-reporter-2
v1.2.1
Published
A testrail reporter for Mocha.js
Readme
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-generatorto be present on the suite, in which themochawesome.jsonfile generated will be used to extract testcases to be uploaded to Testrail. ( Extractor tool added to releases. )Using
multi-custom-reporterwill allow both reporters work together.
Installation
Using NPM:
npm i mocha-testrail-reporter-2Add reporter to mocha.json
- Standalone using mocha-testrail-reporter-2.
{
...,
"reporter": ["mocha-testrail-reporter-2"],
"reporter-options" : "",
...
}- i. Using
multi-custom-reporter(Recommended)
{
...,
"reporter": ["mocha-multi-reporters"],
"reporter-options" : "configFile=config.json",
...
}- ii. Add
config.jsonto root directory of your automation suite if usingmulti-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 protected]",
"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] (optional) 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] (optional) 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",
}- Returning a static version
exports.version = async () => {
return "1.0.0";
}
- 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



Failed tests results on Testrail

Testrail Run with mocha defined

Testrail Run with version defined

Testrail Run with mocha & version defined

