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

API v2 questions


#1

Hello, I’m working on a project to integrate some automated test results into TestRail using the API, I have a couple questions.

  1. Is there a way to get a list of every test in a run (all I really need is ID and type)

  2. How do I figure out the ID of a test case inside a run? I have a test run(202) with an instance of a test case with ID(T6639), but this does not work:
    get_results_for_case/202/6639
    I assume that I have to pass it the original C#### ID from my test suite. but is there a quick way to figure that out just by looking at the run in the UI.?


#2

I answered most of my questions on my own

  1. get_tests/:run_id

  2. option in the UI to view Test ID and Case ID

However I’m still having a hard time adding a result like this:

options = {
:basic_auth => {:username => :password => },
:headers => {“Content-Type” => ‘application/json’},
:body => {“status_id” => ‘2’}
}

response = HTTParty.post(“server/index.php?/api/v2/add_result_for_case/202/1493”, options)


#3

Hello Peter,

Thanks for your posting. Please see below for my answers:

  1. Yes, you can use get_tests for this.

  2. You would use the C# IDs with the _for_case API methods (get_results_for_case, add_result_for_case) and T# IDs for the counter parts (get_results, add_result). Assuming that you have a test with ID 1000 (T1000 in the UI), you can use the following to get and add results:

get_results/1000 add_result/1000

The corresponding _for_case methods then require the run and case IDs.

Regards,
Tobias


#4

Thank you Tobias.

Is there any way to receive a list of all test cases in a run by type? I am trying to get a list of all test cases that are set to be type_id=10.
My current method is this:

  1. /get_tests/ (unfortunately this response doesn’t seem to include the test type)
  2. for each test, I use the case to /get_case/<case_id>
  3. And then I filter the cases that have the type_id that i want
  4. Then I /add_result_for_case/<run_id>/<case_id>

This is all fine and good, except sometimes our test runs are 500+ tests, and step 2 hits the API once for every test in the run, sometimes this can take a a prohibitively long time. (over a minute for every 100 tests) And it probably hammers your API with requests.

Is there a better way of doing this?


#5

Hello Peter,

There’s currently no way to do this more efficiently with the current API unfortunately. I’ve added this as a feature request for now and we will add support for type type_id and additional properties to get_tests in the next update.

Regards,
Tobias


#6

Thanks again. I might try sucking down every test in our system and building a local list of “automated” tests. It’s more data to transfer, but probably a lot faster than 1000 API calls.


#7

Hello Peter,

Yes, this would probably work better and caching the data locally sounds like a good idea.

Regards,
Tobias