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

Add_result_for_case API - Easy way to add results


#1

Hi,

I’m trying to use the TestRail API for automatically logging test results.

Using add_result_for_case, it required a runID. The problem is that I have organized my test cases into about 10 test suites or so. I have created a test plan specifically for automation, when I add each suite to that plan, each one will have a different RunID.

The problem is that it’s not the same RunID for all my test cases and I would need to know which suite the test belongs to and then what the RunID is for that particular suite and so on. As the project grows and even new projects are added this is going to be a big headache to deal with.

Is there any other way to do this? Any tips? Is it at all possible to log test results without specifiying a RunID? I don’t really care for the test result to be tied to a test plan anyway, since this is just going to be automated tests that run regularily so a generic bucket plan is all I need. All I’m after is being able to log the test result from an automated run so I can keep track of the test result history for the particular test case.

Is there any simple way to do this, without having to deal with test plans and run ids, etc.?

Thanks,
Tarik


#2

Also, is there any way to add every test case in a project to a single test run? That would make things simple?

Thanks,
Tarik


#3

Hi Tarik,

Thanks for your posting! A test run is always linked to a single test suite and you would either need the run ID or test ID to submit test results. Do you also start your test run as part of your automated tests? If so, the API response for add_run includes the ID of the run and you can use this ID to submit test results via add_result_for_case.

Cheers,
Tobias


#4

Hi,

No I don’t start a test run as part of the automation. I just want an easy way to log the test run after the automated test execution.

You mentioned I could just use the test Case ID to submit test results? How so?

So is there no way to add every single test case in a project to a test run?

Thanks,
Tarik


#5

Hi Tarik,

You would either need the run ID (R###) or test ID (T###) to submit test results. If you use the same plan to your automated tests, the run IDs are static and don’t change and you can look into storing the run IDs together with your case IDs as part of your automated tests.

A test run is always linked to a specific test suite and can include test cases from this suite. We usually recommend using just a single test suite per project and this is the most flexible setup. TestRail also has a single-suite mode for projects so you have just one single, large case repository:

Cheers,
Tobias


#6

Hi,

Thanks for your reply. I’m using option 3 (use mutliple test suites to manage cases).
I’ll store the Run IDs for each suite since they are static and get the corresponding run id for the test case I want to add the result to.

Just wondering, if I add additional test cases afterwards to a test suite, will the test run automatically be updated to include them? I have the option as select all tests inside of the suite when I configured it?

If so, then adding new test cases to a suite, won’t require any additional work to have the results posted to TestRail.

Thanks,
Tarik


#7

Hi Tarik,

Yes, new cases are automatically added to the runs if you use the include-all option for the case selection. So, instead of configuring a custom case selection when creating the run, you can just choose “Include all test cases” and new cases are automatically added as test to all active runs.

Cheers,
Tobias


#8

Perfect, then I should be good to go. I’ll just have to update my mapping of RunIDs to test suites whenever we add a new test suite.

Thanks so much!


#9

Great to hear that this works for you :slight_smile:

Cheers,
Tobias


#10

Any ideas why this does not work?

from testrail import *

client = APIClient(‘https://xxxxxx.testrail.io/’)
client.user = 'xxxx.xxxxx@xxxxxx.fi’
client.password = ‘xxxxxxxx’

result = client.send_post(
‘add_result_for_case/5/37’,
{ ‘status_id’: 1, ‘comment’: ‘This test worked fine!’ }
)
pprint(result)

testrail.APIError: TestRail API returned HTTP 400 (“Field :case_id is not a valid test case.”)