【问题标题】:Selenium with TestRail Integration with latest versionSelenium 与最新版本的 TestRail 集成
【发布时间】:2021-02-15 12:44:56
【问题描述】:

我正在使用 gurock API 从 Test Rail 获取测试用例状态

下面会返回TC的状态。我会在pom.xml中提供trRunID。并且 TCname 将使用方法 Name 获取。

    public static int FetchTestRailResult(String trRunId, String TCName, String trusername, String trpassword )
                throws MalformedURLException, IOException, APIException {

            int val=0;
            APIClient client = new APIClient($testRailurl);

            client.setUser(trusername);
            client.setPassword(trpassword); 
;
            JSONArray array = (JSONArray) client.sendGet("get_tests/"+trRunId+"&status_id=1");
            
            for (int i = 0; i < array.size(); i++) {
                JSONObject c = (JSONObject) (array.get(i));
                String testrailTestCaseName=c.get("title").toString().split("_")[1];
                if (testrailTestCaseName.equals(TCName)) {
                    val=1;
                    break;
                }
            }
            return val;

        }

下面会更新结果。

public static void UpdateResultToTestRail(String trusername, String trpassword, String trRunId,String testCaseName,String status, String testStepDetails)
        throws MalformedURLException, IOException, APIException {

    APIClient client = new APIClient($testrailurl);
    
    client.setUser(trusername);
    client.setPassword(trpassword); 

    HashMap data = new HashMap();
    data.put("status_id", status);
    data.put("comment", testStepDetails);

    JSONArray array = (JSONArray) client.sendGet("get_tests/"+trRunId);
    //System.out.println(array.size());
    for (int i = 0; i < array.size(); i++) {
        JSONObject c = (JSONObject) (array.get(i));
        String testrailTestCaseName=c.get("title").toString().split("_")[1];
        if (testrailTestCaseName.equals(testCaseName)) {
            System.out.println(c.get("id"));
            client.sendPost("add_result/" + c.get("id"), data);
            break;
        }
    }

}

我现在正在迁移到 maven,现在它具有依赖关系

<!-- https://mvnrepository.com/artifact/com.codepine.api/testrail-api-java-client -->
    <dependency>
      <groupId>com.codepine.api</groupId>
      <artifactId>testrail-api-java-client</artifactId>
      <version>2.0.1</version>
    </dependency>

它没有 api 方法,它有 Builder 和 build 但进一步无法检查连接是否成功。有人在 Maven 中使用过 testrail 吗?

【问题讨论】:

    标签: selenium testrail


    【解决方案1】:

    我没有使用过那个库,但它看起来很容易使用,而且他们的 githib 项目页面上有一些文档:https://github.com/codepine/testrail-api-java-client

    对于您的用例,我认为您只需要执行以下操作:

    TestRail testRail = TestRail.builder("https://some.testrail.net/", "username", "password");
    Tests tests = testRail.tests();
    List<Test> lst = tests.list(runId).execute();
    //filter it based on your conditions
    

    我没有运行代码 - 只是编写它,所以它可能存在一些问题,但应该让您了解如何使用该库。
    请注意,截至 2 月 26 日,TestRail is changing 他们对批量请求(如案例、测试、项目等)的 HTTP 响应,所以我不确定该库是否仍可用于下一个 TR 版本 - 你需要检查一下。

    附:我们正在开发一些与 TestRail 集成的产品,因此您可能想查看它们。如果您有兴趣,请查看我们的产品:
    https://www.agiletestware.com/pangolin
    https://www.agiletestware.com/firefly

    【讨论】:

    • 遇到 SSL 握手错误。正在调试
    • 也许您的 TR 服务器有自签名证书?
    • 解决了..添加了自签名证书..您的代码只需稍作改动即可完美运行。非常感谢。
    【解决方案2】:

    根据您的测试框架(TestNG 的 JUnit),尝试使用以下库之一:

    他们都有关于如何通过几个步骤集成它的 Medium 文章(参见那里的 README.md)

    【讨论】:

    • 赞成。这看起来也不错的解决方案.. 但不幸的是,我们没有在测试用例中添加案例 ID。我们通过匹配测试用例名称来获取测试 ID。
    • 您可以通过导航到相应的测试用例并检查 url 来获取测试用例 ID,它应该是这样的 - your-testrail-link.testrail.io/index.php?/cases/view/3 - 所以 3 是一个 ID,可以在自动测试中匹配
    • 因为我们有 300 多个测试用例.. 需要使用 case id.. 可能如果没有其他选择我们必须这样做...
    • @ChanGan 设置一个 Id - 是 1 次活动,不需要重写或其他东西,所以一旦你做到了 - 你不需要回到它(仅在新测试自动化的情况下),所以我强烈推荐这些库和最有效、快速和简单的方法。
    • 你给的两篇文章,我们需要下载jar,这对我们来说是不可能的,因为我们正在创建maven依赖
    猜你喜欢
    • 2017-11-06
    • 2020-04-25
    • 1970-01-01
    • 2019-01-08
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    相关资源
    最近更新 更多