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

Usage "add_results_for_cases" for updating multiple test cases


#1

was able to use the api “add_result” to update the result for a test case in the below way.

    data.put("run_id", "1234");
        data.put("status_id", 1);
	data.put("comment", "test API");

       JSONObject runAPIResponse = (JSONObject) client.sendPost("add_result/"+Testcase_Id, data); 

the above worked well for me, Now if i want to update the Multiple test cases , i’m getting BAD REQUEST has the error response from the TestRail server. Can you provide some simple example how to implement this?

JSONObject runAPIResponse = (JSONObject) client.sendPost(“add_results_for_cases/”+run_id,data);
Where run_id is the Array of Run id’s like [123,124,125]
data is the object has below:
[ {
“case_id”: 1,
“status_id”: 5,
“comment”: “This test failed”,
“defects”: “TR-7”

                 		},
                 		{
                 			"case_id": 2,
                 			"status_id": 1,
                 			"comment": "This test passed",
                 			"elapsed": "5m",
                 			"version": "1.0 RC1"
                 		}]

#2

Hi Sanjay,

Thanks for your posting. add_results_for_cases and add_results support multiple cases/tests but they must be part of the same test run. So, passing an array of run IDs wouldn’t be possible and you would need to call these API methods in the context of a single test run:

add_results/:run_id
add_results_for_cases/:run_id

Cheers,
Tobias


#3

I wanted to update the test cases for the same Run, So if I change this RunId to point to a single test run than will the below code works?
JSONObject runAPIResponse = (JSONObject) client.sendPost("add_results_for_cases/"+run_id,data);
Where run_id is the Array of Run id’s like [123] and
data is the object has below:
[ {
“case_id”: 1,
“status_id”: 5,
“comment”: “This test failed”,
“defects”: “TR-7”

                     		},
                     		{
                     			"case_id": 2,
                     			"status_id": 1,
                     			"comment": "This test passed",
                     			"elapsed": "5m",
                     			"version": "1.0 RC1"
                     		}]

#4

Any Update on this ?


#5

Hi Sanjay,

If run_id is an array, I’m pretty sure Java wouldn’t format the following expression correctly:

"add_results_for_cases/"+run_id

Please make sure the string you pass to sendPost looks something like this:

"add_results_for_cases/123"

I hope this helps!

Cheers,
Tobias


#6

Yes ‘run_id’ is an array of datatype Object. I’m still not clear what will be the difference between "add_result" and “add_results_for_cases” after looking at your example("add_results_for_cases/123")? is the Data object correct?
[ {
“case_id”: 1,
“status_id”: 5,
“comment”: “This test failed”,
“defects”: “TR-7”

                     		},
                     		{
                     			"case_id": 2,
                     			"status_id": 1,
                     			"comment": "This test passed",
                     			"elapsed": "5m",
                     			"version": "1.0 RC1"
                     		}]

#7

Hi Sanjay,

The issue is likely with the following line:

"add_results_for_cases/"+run_id

TestRail’s API expects "add_results_for_cases/123" but your code will likely format this to something that looks more like "add_results_for_cases/[array]" or similar (the result of the string concat expression with the array). TestRail will respond with a 401 of course because it expects a run ID instead.

I hope this helps!

Cheers,
Tobias


#8

Yes TestRail responded 401 error code. Can you please tell me how will the sample request( along with the Header information) should look like to update multiple test cases present in the same test run?


#9

Any Updates ?

it will be helpful if you can share us the request header along with the sample request URL for using this API.


#10

Hi Sanjay,

Sorry, I meant 400 status code instead of 401 (401 would mean authentication issue instead). You can find a full example here in our documentation:

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

The expected headers are the same as for all requests but this is handled automatically by sendPost anyway. I just want to point out again that the following expression in your code looks incorrect if run_id is in fact an array:

"add_results_for_cases/"+run_id

Cheers,
Tobias


#11

Hi Tobias

Actually i’m storing my Run_ID & Case_ID in a seperate variables and want them to use in my sensPost request like below. But it was not allowing me to update the results.

JSONObject s = (JSONObject) client.sendPost(“add_result_for_case/”+Case_ID"/"+run_ID, data);

Can you please help me with this.

Thanks
Tharun


#12

I used the same API to update the multiple test cases results.
I believe you need to remove off the case id, instead you need to have the run id.
/testrail/index.php?/api/v2/add_results_for_cases/xx

where :
xx - run id
xxx - case id

Json body as below:
{
“results”: [
{
“case_id”: xxx ,
“status_id”: 5,
“comment”: “This test failed”,
},
{
“case_id”: xxx
"status_id": 1,
“comment”: “This test passed”,
}
]
}


#13

Thanks for the response sanjay.

What im trying to do is, once the execution was done, my script should pass the result and api should automatically fetch and store the run_ID & case_ID automatically from TestRail in separate variables.

run_ID=7267
Case_ID=504541

JSONObject s = (JSONObject) client.sendPost(“add_result_for_case/7267/504541”, data);

How should i give the above parameters in my method. This is my question. can u please help me with this. Instead of hard coding the values i just wanna pass as a parameter.

Let me know if you have any questions


#14

Hi,

Thank you for the additional information. In this case, I would recommend taking a look at our API documentation again located here:

http://docs.gurock.com/testrail-api2/start

Also, depending on how you are sending the request, this can determine the best way to pass those variables. Is it also possible you have a team member that can help with this or has some understanding of API programming as well?