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

Updating seperate steps through Java API


#1

Map data = new HashMap<String,String>();
data.put(“status_id”, new Integer(5));
data.put(“comment”, “This test FAILED!”);
data.put(“custom_steps_seperated”,"[{“status_id”: “1”},{“status_id”: “1”}]");

JSONObject res = (JSONObject) client.sendPost(“add_result_for_case/508/106357”, data);

When I execute this code I only update the test case not the individual steps.

Please Help,
Thank you


#2

Hello David,

Thanks for your posting. I believe this is just a typo for the field name. The steps field according to our documentation uses ‘steps_separated’ as system name (note the ‘a’ instead of ‘e’). Can you confirm that you can see ‘steps_separated’ under Administration > Customizations. The field name for the API call would then be ‘custom_steps_separated’ accordingly.

I hope this helps!

Regards,
Tobias


#3

Map data = new HashMap<String,String>();
data.put(“status_id”, iVal);
data.put(“comment”, sVal);
data.put(“custom_steps_separated”,"[{“status_id”: “1”},{“status_id”: “1”}]");

JSONObject res = (JSONObject) client.sendPost(“add_result_for_case/508/106357”, data);

I changed the name, but i am still not getting the steps


TestRail API Parameter Issue
#4

Thanks, David.

I just saw that you using a string for the steps data and you would need to use a structured approach instead. You would need to format the steps list as an array (List) of dictionaries (Map) and this looks similar to the data variable:

[code]List steps = new ArrayList()
Map step1 = new HashMap()
step1.put(“status_id”, new Integer(1))
step1.put(“content”, "Steps content … ")
Map step2 = …
steps.add(step1)
steps.add(step2)

data.put(“custom_steps_separated”, steps)[/code]

(pseudo code)

I hope this helps!

Regards,
Tobias


#5

Hi,

I tried using both the approaches as given above.
It still isn’t happening for me.

Morever It always gives me error:400 when I try using the command
add_result_for_case/508/106357 where first id is run id and second id is test case id.

Please help me.

Thanks.


#6

Hello Dharna,

Thanks for your posting. Please have a look at the error message that should be included as part of the response by TestRail (e.g. something like “Unknown or invalid test run”). This should help troubleshooting this issue.

Regards,
Tobias


#7

Hey Tobias,

Thanks for responding.
I am now able to do it using the command add_result/177 in which 177 is my test_id.
I cross verified it using get_results as well. The id for test run is id=47 and test id is test_id=177.

Response for reference
"{“elapsed”:null,“status_id”:4,“created_on”:1433407924,“defects”:null,“assignedto_id”:null,“comment”:“In Progress from selenium”,“id”:47,“created_by”:1,“version”:null,“custom_step_results”:null,“test_id”:177},"

But still for command add_result_for_case/508/106357 …it give an error saying my run id is not valid.

I am trying to use 177 which is test_id and 14 which is case_id as add_result_for_case/177/14.

My code is as below:

    List steps = new ArrayList();
   
    Map data = new HashMap();
  
    Map step1 = new HashMap();
    step1.put("status_id", new Integer(5));
    step1.put("content", "Step 1");
    step1.put("expected", "desc2");
    step1.put("actual", "Actual Result 1 FROM TEST SELENIUM");
    steps.add(step1);

     data.put("status_id", new Integer(4));
    data.put("comment", "In Progress from selenium");
    data.put("custom_step_results", steps);

   JSONObject r = (JSONObject) client.sendPost("add_result/177", data);  //(Works Fine)

    //JSONObject r = (JSONObject) client.sendPost("add_result_for_case/177/14", data); //Problem
   //or 
  JSONObject r = (JSONObject) client.sendPost("add_result_for_case/47/14", data); //Problem

When I run the code:

error:
Exception in thread “main” testrailpackage.APIException: TestRail API returned HTTP 400(“Field :run_id is not a valid test run.”)

I am unable to judge what I am doing wrong here.

Also custom_steps_separated doesn’t works with anything so I changed it to custom_step_results which I got as a part of response also from get_result and it worked fine for first instance.

Thanks.


#8

Recheck the run id - from the above it does not look like it is correct.


#9

Hi,

I attached complete response for your reference from get_Results.
I am using valid run-id.It’s still not happening.

Can you please look into code closely once and respond.

Regards,
Dharna


#10

Hello Dharna!

You would need to use ID 47 in this case (as this is the ID of the test run, 177 refers to the test):

add_result_for_case/47/14

Could you try this please?

Regards,
Tobias