1

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("https://stdec.testrail.com/");
        client.setUser("fea@sportdec.com");
        client.setPassword("Fa1");

        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);
        map.put({"17082","17085"});
        client.sendPost("index.php?/api/v2/add_run/24", map);

        return jsonobject;
    }
}

The testrail documentation is here im looking for the add run http://docs.gurock.com/testrail-api2/reference-runs 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

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
  • See the sample [here](http://docs.gurock.com/testrail-api2/bindings-java#examplepost_request). You have to call `client.sendPost` – Master Po Jul 13 '18 at 10:22
  • Ive updated the code but im getting : com.gurock.testrail.APIException: TestRail API returned HTTP 500("Invalid characters in URI: [/api/v2/index_php?/api/v2/add_run/24]") – fearghal O reilly Jul 13 '18 at 10:29
  • Updated code above..how would you write it in java thsi is very new for me – fearghal O reilly Jul 13 '18 at 10:30
  • that error message is telling you the request URL is bad. looking at the doc, perhaps you are missing the : "index.php?/api/v2/add_run/:24" – Breaks Software Jul 13 '18 at 11:18
  • Ive changed the code again but now struggling to get . a list working in this – fearghal O reilly Jul 13 '18 at 11:58
  • How am i suppose to put all the objects into the JSON when its only asking for a string in place of the map – fearghal O reilly Jul 13 '18 at 12:00
  • 1
    Suggestion, try to put request in some tool first, Postman... or similar. – Kovacic Jul 17 '18 at 12:07
  • This is the problem: client.sendPost("index.php?/api/v2/add_run/24", map); Here in you are passing the rest of the API url which API CLIENT.java is adding automatically and you need to the add the API method URL like client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data ); – Atul KS Aug 31 '20 at 17:37
  • @fearghalOreilly Now you can use the TRCLI (TestRail CLI) to get around this problem and avoid unnecessary code. Please refer this answer for details - https://stackoverflow.com/a/76809919/1502300 – virulent-slash Aug 01 '23 at 08:54

1 Answers1

1

Have sorted this problem by :

public static String TEST_RUN_ID                = "27";
public static String TESTRAIL_USERNAME          = "xxx@yahoo.com";
public static String TESTRAIL_PASSWORD          = "jdNnNt0OKyNnVA0BW";
public static String RAILS_ENGINE_URL           = "https://axulxharmx.testrail.io/";
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);
      client.setUser(TESTRAIL_USERNAME);
      client.setPassword(TESTRAIL_PASSWORD);
    
      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.

Atul KS
  • 908
  • 11
  • 21