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

Python API Question


#1

Hello all,

I’m fiddling with the TestRail API for automation, using Python. I have the binding setup, but am having some issues with the add_results call.

Below is the what I’m sending in the POST, following the instructions in the documentation:

I can say with certainty that the Run ID (4) and the test case IDs are correct, yet I receive an error stating:

HTTP 400 (“Field :results cannot be empty but no valid test cases found”).

Thoughts? Am I missing something?


#2

Hi Dan,

Thanks for your posting. add_results requires the test ID (T### in the UI). If you have the case IDs instead (C###), you can use add_results_for_cases in combination with the run ID:

http://docs.gurock.com/testrail-api2/reference-results#add_results_for_cases

Cheers,
Tobias


#3

Hi Tobias
I have a question about add_results method.
According to your comment, we can’t use this method with case IDs, can we?
So how can I perform bulk posting of test results with automation tests. I can get only the Case IDs, because the Get method doesn’t return the Test IDs (moreover it is not convenient for automation testing).


#4

Hi Magadan,

Yes, add_results only works with the test IDs (T###) but there’s an equivalent version for case IDs (C###) as well: add_results_for_cases:

http://docs.gurock.com/testrail-api2/reference-results#add_results_for_cases

As you mentioned, this is better in situations where you need a static ID (in automation scenarios) and also the intended use case of this method.

I hope this helps!

Cheers,
Tobias


#5

It’s a good news for me, I missed that point.
Thank you very much for your advice!
Enjoy your day!


#6

Only one comment - the exception is caught after using the add_results_for_cases method, but the SendRequest ran normally (without exception).


#7

Hi Magadan,

Thanks for your reply! SendRequest would rethrow any exception. Which API binding do you use? .NET/C#?

Cheers,
Tobias


#8

I have C# project and use the following API
When I used the add_results_for_case it worked without exceptions.


#9

Hi Magadan,

add_results_for_cases would expect the case IDs and add_results expects the test IDs so it’s expected that one of them would work and the other wouldn’t if you use the same IDs with both API methods. SendRequest would throw any exception/error code returned by TestRail and the error message includes a description and the HTTP error code (you can look up possible errors as part of the API description).

I hope this helps!

Cheers,
Tobias


#10

Hi Tobias,
Thanks for your answers!
I have the TestRail plan which includes some runs. I use the add_results_for_cases method for posting results.
Here is part of code try { c = (JObject)client.SendPost("add_plan_entry/" + TestRailData["run_id"], TestRailData); c = (JObject)client.SendGet("get_plan/" + TestRailData["run_id"] + "/" + "entries/runs/id"); ... c = (JObject)client.SendPost("add_results_for_cases/" + runId, result); } catch { return false; } return true;

The last post add_results_for_cases/ method returns the post string, like this
{{ "id": 763, "name": "TestPlan", "description": null, "milestone_id": null, "assignedto_id": null, "is_completed": false, "completed_on": null, "passed_count": 2097, "blocked_count": 0, "untested_count": 1057, "retest_count": 0, "failed_count": 288, "custom_status1_count": 0, "project_id": 18, "created_on": 1464179873, "created_by": 11, "url": "https://......testrail.com/index.php?/plans/view/763", "entries": [ { "id": "19daa106-8c0c-4112-97bd-a1e7a3a43f76", "suite_id": 649, "name": "Test_06071200", "runs": [ { "id": 825, "suite_id": 649, "name": "Test_06071200", "description": null, "milestone_id": null, "assignedto_id": null, "include_all": true, "is_completed": false, "completed_on": null, "passed_count": 14, "blocked_count": 0, "untested_count": 13, "retest_count": 0, "failed_count": 0, "custom_status1_count": 0, "project_id": 18, "plan_id": 763, "entry_index": 1, "entry_id": "19daa106-8c0c-4112-97bd-a1e7a3a43f76", "config": null, "config_ids": [], "created_on": 1465290249, "created_by": 11, "url": "https://.....testrail.com/index.php?/runs/view/825" } ] }, }}

This text is interpreted as an exception error text and as a result, my method returns false.
When I used the following post string
c = (JObject)client.SendPost("add_result_for_case/" + runId + "/" + TestCases[results.Key], TestRailData);
the method returns true.
Could you suggest where the issue is?
Thanks in advance!


#11

Hi Magadan,

Thanks for your reply! I’m not sure about the content of TestRailData vs result so this is difficult to tell. You can look at the expected format and supported attributes of add_results_for_cases as part of your API documentation:

http://docs.gurock.com/testrail-api2/reference-results

Cheers,
Tobias