用Java为测试轨创建Post Api

用Java为测试轨创建Post Api,java,api,selenium,testing,testrail,Java,Api,Selenium,Testing,Testrail,我正在尝试创建一个java post请求,以在测试轨道上创建测试运行,但它似乎不起作用。下面是我的代码: public class create_run { public JSONObject AddTestRunTest() throws IOException, APIException { JSONObject jsonobject = new JSONObject(); APIClient client = new APIClient("

我正在尝试创建一个java post请求,以在测试轨道上创建测试运行,但它似乎不起作用。下面是我的代码:

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;
    }
}
public类创建\u运行{
publicJSONObject AddTestRunTest()抛出IOException,APIException{
JSONObject JSONObject=新的JSONObject();
APIClient客户端=新的APIClient(“https://stdec.testrail.com/");
client.setUser(“fea@sportdec.com");
客户端设置密码(“Fa1”);
Map Map=newhashmap();
地图.put(“suite_id”,829);
地图放置(“分配到_id”,1);
map.put(“名称”、“回归测试”);
map.put(“include_all”,true);
map.put({“17082”,“17085”});
client.sendPost(“index.php?/api/v2/add_run/24”,map);
返回jsonobject;
}
}
testrail文档在这里,我正在寻找添加运行
在这里,任何关于如何使其真正起作用的帮助都已经完成,但什么都没有发生。我是一名测试人员,但我正在努力解决这一问题,我通过以下方式解决了这个问题:

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 );

}

**它在java代码和POSTMAN中运行良好,并将结果推送到我的TestRail实例。

参见示例。你必须调用
client.sendPost
i更新了代码,但我得到了:com.gurock.testrail.APIException:testrail API返回了HTTP 500(“URI中的无效字符:[/API/v2/index\u php?/API/v2/add\u run/24])上面更新的代码..你将如何用java编写它thsi是非常新的,因为Metat错误消息告诉你请求URL不正确。查看文档,可能您缺少了“index.php?/api/v2/add_run/:24”建议,请先尝试将请求放入某个工具中,邮递员。。。或类似的。