Skip to content

Create Post Api in Java for Test Rail

Im trying to create a java post request to create a test run on test rail, however it doesn’t seem to be working heres my code:

public class create_run {
    public JSONObject AddTestRunTest() throws IOException, APIException {
        JSONObject jsonobject = new JSONObject();
        APIClient client = new APIClient("");
        client.setUser("[email protected]");

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("suite_id", 829);
        map.put("assignedto_id", 1);
        map.put("name", "Regression Test");
        map.put("include_all", true);
        client.sendPost("index.php?/api/v2/add_run/24", map);

        return jsonobject;

The testrail documentation is here im looking for the add run Any help here how to make this actually work , is completing but nothing is happening. I’m a tester but struggling with this pat of the Java


Have sorted this problem by :

public static String TEST_RUN_ID                = "27";
public static String TESTRAIL_USERNAME          = "[email protected]";
public static String TESTRAIL_PASSWORD          = "jdNnNt0OKyNnVA0BW";
public static String RAILS_ENGINE_URL           = "";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;

     public static void addResultForTestCase(String testCaseId, int status,
        String error) throws IOException, APIException {

       String testRunId = TEST_RUN_ID;

      APIClient client = new APIClient(RAILS_ENGINE_URL);
      HashMap data = new HashMaps();
      data.put("status_id", status);
    data.put("comment", "Test Executed- Status updated test automation framework.");
    client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );


**It’s working fine in java code as well as POSTMAN and pushing the results to my TestRail instance.