【问题标题】:How to add test cases to an existing test run with the API from Java to TestRail?如何使用从 Java 到 TestRail 的 API 将测试用例添加到现有的测试运行中?
【发布时间】:2019-03-20 00:36:15
【问题描述】:

我在执行期间创建了一个测试运行,我想在它们开始执行的同时添加测试用例。测试用例已经创建,如果它们已经不存在的话。并且应该将此测试用例与其他测试用例一起添加到现有的测试运行中。

我尝试在运行和更新运行后使用setCaseIds,但这会覆盖现有运行。我认为错误是因为我使用的是setCaseIds,但我不知道正确的做法。

Case mycase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(section.getId());
mycase = testRail.cases().add(mycase.getSectionId(), mycase, customCaseFields).execute();
final List<Integer> caseToAdd = new ArrayList();
caseToAdd.add(mycase.getId());
run.setCaseIds(caseToAdd);
run = testRail.runs().update(run).execute();
//The first test start the execution
.
.
.
// The first test case finish
// Now I create a new testcase to add
Case mySecondCase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(section.getId());
mycase = testRail.cases().add(mySecondCase.getSectionId(), mySecondCase, customCaseFields).execute();
// I repeat the prevous steps to add a new test case
final List<Integer> newCaseToAdd = new ArrayList();
newCaseToAdd.add(mySecondCase.getId());
    run.setCaseIds(newCaseToAdd);
    run = testRail.runs().update(run).execute();

有人知道怎么做吗?提前谢谢你。

【问题讨论】:

    标签: java api selenium automation testrail


    【解决方案1】:

    这是我能找到的:

    1. TestRail 不支持添加/追加操作。它只支持设置/覆盖操作。这就是您在同一运行中调用 setCaseIds 两次时会发生的情况,它只保存最后一个 id(这就是您通常可以从 set 方法中得到的结果)。
    2. 建议的解决方案是:

    Run activeRun = testRail.runs().get(1234).execute(); List<Integer> testCaseIds = activeRun.getCaseIds() == null ? new ArrayList<>() : new ArrayList<>(activeRun.getCaseIds()); testCaseIds.add(333); testRail.runs.update(activeRun.setCaseIds(testCaseIds)).execute();

    因此,您可以从 run 中获取现有的 id,而不是设置一个新的 id,向它添加 id 并更新 run。

    来源: https://github.com/codepine/testrail-api-java-client/issues/24

    【讨论】:

    • 感谢您的回答@vladimir-efimov。我不敢相信 TestRail 团队不支持这个功能,这太不可思议了。在我看来,这是基本功能。
    • @j.barrio 如果我没记错的话,TestRail 团队不支持 testrail-api-java-client。它只是一个开源项目github.com/codepine/testrail-api-java-client。因此,您实际上可以提交请求支持此类功能的问题,然后提交包含更改的拉取请求;)。这是官方 TR api docs.gurock.com/testrail-api2/reference-runs 的文档。您实际上可以直接使用它,但您必须自己实现 auth+send 请求。
    【解决方案2】:

    我解决了计划和条目结构的问题。我将所有测试用例保存在一个列表中,这个列表作为参数传递给entry.setCaseIds 函数:

    // First Test Case
    Case mycase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(section.getId());
    mycase = testRail.cases().add(mycase.getSectionId(), mycase, customCaseFields).execute();
    // List for Test Cases
    List<Integer> caseList = new ArrayList<>();
    caseList.add(mycase.getId());
    // Create new Entry and add the test cases
    Entry entry = new Entry().setIncludeAll(false).setSuiteId(suite.getId()).setCaseIds(caseList);
    entry = testRail.plans().addEntry(testPlan.getId(),entry).execute();
    // Create the second test case
    Case mycase2 = new Case().setTitle("TEST TITLE 2").setSuiteId(suite.getId()).setSectionId(section.getId());
    mycase2 = testRail.cases().add(mycase.getSectionId(), mycase, customCaseFields).execute();
    // Add the second test case to the list
    caseList.add(mycase2.getId());
    // Set in the Entry all the test cases and update the Entry
    entry.setCaseIds(caseList);
    testRail.plans().updateEntry(testPlan.getId(), entry).execute();
    

    要执行测试用例,您需要运行测试:

    run = entry.getRuns().get(0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 2022-10-19
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      相关资源
      最近更新 更多