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

API Adding Test cases using JAVA


#1

I am trying to add test cases using Java to hit the API

the following is the code im using

Map data = new HashMap();
data.put(“title”, title);
data.put(“template_id”, “1”);
data.put(“type_id”, “3”);
data.put(“priority_id”, “2”);
data.put(“custom_test_steps”, steps);
data.put(“custom_description”, desc);
data.put(“custom_objective”, objctv);

JSONObject r = (JSONObject) client.sendPost(“add_case/2”, data);

I am getting
Exception in thread “main” com.gurock.testrail.APIException: TestRail API returned HTTP 400(“Field :custom_test_steps is not a valid array.”)

A printout of the steps variable is
[{“content”:“ewffwef”,“expected”:“ewffwef”},{“content”:“Validation Input”,“expected”:“Validation Expected result”}]

This seems to follow the syntax in the example, please help


#2

NM figured it out wasn’t parsing to a JsonArray type


#3

Hello Jesse,

Thanks for your posting! You can also find a fully working example for the steps + Java here:

Cheers,
Tobias