Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

[UI Script] Accessing TestRail's API via JavaScript


#1

The following example accesses TestRail’s API via JavaScript. Requires session authentication support (can be enabled under Administration > Site Settings > API in TestRail).

Learn more about TestRail’s API and UI Scripts:

http://docs.gurock.com/testrail-api2/start
http://docs.gurock.com/testrail-custom/uiscripts-introduction

[code]name: Example API request
description: Demonstrates how to use the API via JavaScript
author: Gurock Software
version: 1.0
includes: ^suites/view
excludes:

js:
(document).ready( function() { .ajax(
{
url: uiscripts.env.page_base + ‘/api/v2/get_suite/’ + uiscripts.context.suite.id,
dataType: ‘json’,
beforeSend: function(xhr)
{
xhr.setRequestHeader(“Content-Type”, “application/json”);
xhr.setRequestHeader(“X-Requested-With”, “API Client”);
},
success: function(data, status)
{
console.log(data); // Contains the suite
},
error: function(error)
{
console.log(error);
}
});
}
);[/code]

Regards,
Tobias


GET API Error - Response for preflight has invalid HTTP status code 400
Update test run description via UI script
Why is uiscripts.context.suite undefined while editing an existing suite?
Ability to use App object