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

Use Testrail api via Python to get all test cases


#1

I’ve been using the Testrail API (Python bindings) successfully for a week or more. However, I’m stumped on one API request:

API:
GET index.php?/api/v2/get_cases/:project_id \
&suite_id=:suite_id
&section_id=:section_id

Python interpretation:
client.send_get(‘get_sections/1 \6’)

I’ve tried different formatting of the Python command to executing this api, but keep getting a similar error:
Traceback (most recent call last):
File “<pyshell#15>”, line 1, in
client.send_get(‘get_sections/1 \6’)
File “E:\Python\WinPython-32bit-3.4.3.5\testrail.py”, line 36, in send_get
return self.__send_request(‘GET’, uri, None)
File “E:\Python\WinPython-32bit-3.4.3.5\testrail.py”, line 86, in __send_request
(e.code, error))
testrail.APIError: TestRail API returned HTTP 400 (No additional error message received)

Can someone please give me some direction on this? Thanks.


#2

Hello Del,

Thanks for your posting. The backslash (\) character in the example is considered a line break (to make the example more readable) and you wouldn’t include this in the actual API request.

If you want to filter for all cases in section 3 in suite 2 of project 1, you can simply specify this as follows:

GET index.php?/api/v2/get_cases/1&suite_id=2&section_id=3

Or as code:

client.send_get('get_cases/1&suite_id=2&section_id=3')

The same behavior applies to get_sections:

http://docs.gurock.com/testrail-api2/reference-sections#get_sections

Note that the suite ID is optional/ignored if your project uses the (default) single-suite mode with a single case repository.

I hope this helps!

Cheers,
Tobias


#3

Thanks for the clarity…


#4

Sure, glad to help!

Cheers,
Tobias