testrail-api
An API wrapper for TestRail with error handling and unit testing.
The TestRail API is described here.
Usage
First, you will have to initialize the API wrapper :
var Testrail = require('testrail-api');
var testrail = new Testrail({
host: 'https://rundef.testrail.com',
user: 'username',
password: 'password or api key'
});
Callback
Working with callbacks gives you three parameters: error
, response
and body
in this order
function (err, response, body)
error
is null when nothing unexpected happened.
response
contains data like the status code.
body
contains the response body the server sent back.
Promises
Working with Promises gives you response
and body
like this
.then(function (result) {
console.log(result.response);
console.log(result.body);
})
.catch(function (error) {
console.log(error.response);
console.log(error.message);
});
Cases
List cases
testrail.getCases(1, { suite_id: 3, section_id: 4 }, function (err, response, cases) {
console.log(cases);
});
You can also use Promises with all the functions:
testrail.getCases(1)
.then(function (result) {
console.log(result.body);
}).catch(function (error) {
console.log('error', error.message);
});
Get a case
testrail.getCase(1, function (err, response, testcase) {
console.log(testcase);
});
Add a case
testrail.addCase(1, {}, function (err, response, testcase) {
console.log(testcase);
});
Update a case
testrail.updateCase(1, {}, function (err, response, testcase) {
console.log(testcase);
});
Delete a case
testrail.deleteCase(1, function (err, response, body) {
console.log(body);
});
Case Fields
List case fields
testrail.getCaseFields(function (err, response, caseFields) {
console.log(caseFields);
});
Case Types
List case types
testrail.getCaseTypes(function (err, response, caseTypes) {
console.log(caseTypes);
});
Configurations
List configurations
testrail.getConfigs(1, function (err, response, configs) {
console.log(configs);
});
Add a configuration group
testrail.addConfigGroup(1, {}, function (err, response, config_group) {
console.log(config_group);
});
Add a configuration
testrail.addConfig(1, {}, function (err, response, config) {
console.log(config);
});
Update a configuration group
testrail.updateConfigGroup(1, {}, function (err, response, config_group) {
console.log(config_group);
});
Update a configuration
testrail.updateConfig(1, {}, function (err, response, config) {
console.log(config);
});
Delete a configuration group
testrail.deleteConfigurationGroup(1, function (err, response, body) {
console.log(body);
});
Delete a configuration
testrail.deleteConfig(1, function (err, response, body) {
console.log(body);
});
Milestones
List milestones
testrail.getMilestones(1, {}, function (err, response, milestones) {
console.log(milestones);
});
Get a milestone
testrail.getMilestone(1, function (err, response, milestone) {
console.log(milestone);
});
Add a milestone
testrail.addMilestone(1, {}, function (err, response, milestone) {
console.log(milestone);
});
Update a milestone
testrail.updateMilestone(1, {}, function (err, response, milestone) {
console.log(milestone);
});
Delete a milestone
testrail.deleteMilestone(1, function (err, response, body) {
console.log(body);
});
Plans
List plans
testrail.getPlans(1, {}, function (err, response, plans) {
console.log(plans);
});
Get a plan
testrail.getPlan(1, function (err, response, plan) {
console.log(plan);
});
Add a plan
testrail.addPlan(1, {}, function (err, response, plan) {
console.log(plan);
});
Add a plan entry
testrail.addPlanEntry(1, {}, function (err, response, plan_entry) {
console.log(plan_entry);
});
Update a plan
testrail.updatePlan(1, {}, function (err, response, plan) {
console.log(plan);
});
Update a plan entry
testrail.updatePlanEntry(1, 2, {}, function (err, response, plan_entry) {
console.log(plan_entry);
});
Close a plan
testrail.closePlan(1, function (err, response, plan) {
console.log(plan);
});
Delete a plan
testrail.deletePlan(1, function (err, response, body) {
console.log(body);
});
Delete a plan entry
testrail.deletePlanEntry(1, 2, function (err, response, body) {
console.log(body);
});
Priorities
testrail.getPriorities(function (err, response, priorities) {
console.log(priorities);
});
Projects
List projects
testrail.getProjects({}, function (err, response, projects) {
console.log(projects);
});
Get a project
testrail.getProject(1, function (err, response, project) {
console.log(project);
});
Add a project
testrail.addProject({}, function (err, response, project) {
console.log(project);
});
Update a project
testrail.updateProject(1, {}, function (err, response, project) {
console.log(project);
});
Delete a project
testrail.deleteProject(1, function (err, response, body) {
console.log(body);
});
Results
Get results
testrail.getResults(1, {}, function (err, response, results) {
console.log(results);
});
Get results for case
testrail.getResultsForCase(1, 2, {}, function (err, response, results) {
console.log(results);
});
Get results for run
testrail.getResultsForRun(1, {}, function (err, response, results) {
console.log(results);
});
Add a result
testrail.addResult(1, {}, function (err, response, result) {
console.log(result);
});
Add a result for case
testrail.addResultForCase(1, 2, {}, function (err, response, result) {
console.log(result);
});
Add results
testrail.addResults(1, {}, function (err, response, results) {
console.log(results);
});
Add results for cases
testrail.addResultsForCases(1, {}, function (err, response, results) {
console.log(results);
});
Result Fields
testrail.getResultFields(function (err, response, resultFields) {
console.log(resultFields);
});
Runs
List runs
testrail.getRuns(1, {}, function (err, response, runs) {
console.log(runs);
});
Get a run
testrail.getRun(1, function (err, response, run) {
console.log(run);
});
Add a run
testrail.addRun(1, {}, function (err, response, run) {
console.log(run);
});
Update a run
testrail.updateRun(1, {}, function (err, response, run) {
console.log(run);
});
Close a run
testrail.closeRun(1, function (err, response, run) {
console.log(run);
});
Delete a run
testrail.deleteRun(1, function (err, response, body) {
console.log(body);
});
Sections
List sections
testrail.getSections(1, {}, function (err, response, sections) {
console.log(sections);
});
Get a section
testrail.getSection(1, function (err, response, section) {
console.log(section);
});
Add a section
testrail.addSection(1, {}, function (err, response, section) {
console.log(section);
});
Update a section
testrail.updateSection(1, {}, function (err, response, section) {
console.log(section);
});
Delete a section
testrail.deleteSection(1, function (err, response, body) {
console.log(body);
});
Statuses
testrail.getStatuses(function (err, response, statuses) {
console.log(statuses);
});
Suites
List suites
testrail.getSuites(1, function (err, response, suites) {
console.log(suites);
});
Get a suite
testrail.getSuite(1, function (err, response, suite) {
console.log(suite);
});
Add a suite
testrail.addSuite(1, {}, function (err, response, suite) {
console.log(suite);
});
Update a suite
testrail.updateSuite(1, {}, function (err, response, suite) {
console.log(suite);
});
Delete a suite
testrail.deleteSuite(1, function (err, response, body) {
console.log(body);
});
Templates
testrail.getTemplates(1, function (err, response, template) {
console.log(template);
});
Tests
List tests
testrail.getTests(1, {}, function (err, response, tests) {
console.log(tests);
});
Get a test
testrail.getTest(1, function (err, response, test) {
console.log(test);
});
Users
List users
testrail.getUsers({}, function (err, response, users) {
console.log(users);
});
Get a user
testrail.getUser(1, function (err, response, user) {
console.log(user);
});
Get a user by email
testrail.getUserByEmail('test@gmail.com', function (err, response, user) {
console.log(user);
});