JavaScript client for TestRail API
npm install testrail-api-clientTypeScript and JavaScript binding for TestRail API v2



Using npm:
``bash`
$ npm install testrail-api-client
Using yarn:
`bash`
$ yarn add testrail-api-client
#### Using Environment Variables:
`js`
const client = require("testrail-api-client");
#### Using Custom Options:
`js
const client_options = require("testrail-api-client").default;
const options = {
domain: "example.testrail.com",
username: "example@example.com",
password: "ABC",
};
const client = new client_options(options);
`
`jsCreated run with id: ${runId}
const runName = "Example Run Name";
const runDescription = "Example Run Description";
const projectId = 1;
const testSuiteId = 123; // optional
const caseIds = [1, 2, 3]; // optional
const milestoneId = 4; // optional
const refs = "ref"; // optional
client
.addRun(runName, runDescription, projectId, testSuiteId, caseIds, milestoneId, refs)
.then(function (runId) {
console.log();`
})
.catch((error) => console.error(error));
`jsNumber of cases from run #${runId}: ${cases.length}
const runId = 123;
client
.getTests(runId)
.then(function (cases) {
console.log();`
})
.catch((error) => console.error(error));
`jsClosed run with id: ${runId}
const runId = 123;
client
.closeRun(runId)
.then(console.log())`
.catch((error) => console.error(error));
`jsNumber of cases in suiteid=${suiteId}: ${cases.length}
const projectId = 1;
const suiteId = 123; // optional
client
.getCases(projectId, suiteId)
.then(function (cases) {
console.log();`
})
.catch((error) => console.error(error));
`js`
const runId = 123;
const reportTests = [{ case_id: 12345, status_id: 1, comment: "Test comment" }];
client
.addResultsForCases(runId, reportTests)
.then(() => {
console.log("Done");
})
.catch((err) => {
console.log(err);
});
`js`
const runId = 123;
const description = "Run Description";
client
.updateRunDescription(runId, description)
.then(() => {
console.log("Done");
})
.catch((err) => {
console.log(err);
});
`js`
const runId = 123;
client
.addAttachmentToResult(runId, '../testrail-api-client/README.md')
.then((response) => {
console.log("Done", response);
})
.catch((err) => {
console.log(err);
});
| Variable | Description |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| TESTRAIL_DOMAIN | This is a required variable to point the client to your TestRail instance.
_Required_
Example: example.testrail.com |example@example.com
| TESTRAIL_USERNAME | This is a required variable to authenticate HTTP communication.
_Required_
Example: |ABC
| TESTRAIL_APIKEY | This is a required variable to authenticate HTTP communication. Can be obtained in TestRail settings, see [http://docs.gurock.com/testrail-api2/accessing].
_Required_
Example: |1` |
| TESTRAIL_PROJECTID | This is a required variable to point client to the right project.
_Required_
Example: