【问题标题】:Create Post Api in Java for Test Rail在 Java 中为 Test Rail 创建 Post Api
【发布时间】:2018-07-13 10:15:49
【问题描述】:

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

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

测试轨文档在这里我正在寻找添加运行http://docs.gurock.com/testrail-api2/reference-runs 这里的任何帮助如何使它真正起作用,正在完成,但没有任何事情发生。我是一名测试人员,但正在为 Java 的这一块苦苦挣扎

【问题讨论】:

  • 查看示例here。你必须打电话给client.sendPost
  • 我更新了代码,但我得到:com.gurock.testrail.APIException: TestRail API 返回 HTTP 500("URI 中的无效字符:[/api/v2/index_php?/api/v2/add_run /24]")
  • 更新了上面的代码..你怎么用java写它对我来说是很新的
  • 该错误消息告诉您请求 URL 不正确。查看文档,也许您缺少:“index.php?/api/v2/add_run/:24”
  • 建议,先尝试将请求放入某个工具,邮递员...或类似的。

标签: java api selenium testing testrail


【解决方案1】:

已按以下顺序对这个问题进行了排序:

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 实例。

【讨论】:

    猜你喜欢
    • 2018-02-03
    • 1970-01-01
    • 2012-11-19
    • 2017-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 1970-01-01
    相关资源
    最近更新 更多