Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用从Java到TestRail的API将测试用例添加到现有的测试运行中?_Java_Api_Selenium_Automation_Testrail - Fatal编程技术网

如何使用从Java到TestRail的API将测试用例添加到现有的测试运行中?

如何使用从Java到TestRail的API将测试用例添加到现有的测试运行中?,java,api,selenium,automation,testrail,Java,Api,Selenium,Automation,Testrail,我已经在执行期间创建了一个测试运行,我想在它们开始执行的同时添加测试用例。测试用例已经创建,如果它们已经不存在的话。这个测试用例应该和其他测试用例一起添加到现有的测试运行中 我尝试在运行期间和更新运行之后使用setCaseIds,但这会覆盖现有运行。我认为错误是因为我使用的是setCaseIds,但我不知道正确的方法 Case mycase = new Case().setTitle("TEST TITLE").setSuiteId(suite.getId()).setSectionId(sec

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

我尝试在运行期间和更新运行之后使用
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();
Case mycase=new Case().setTitle(“测试标题”).setSuiteId(suite.getId()).setSectionId(section.getId());
mycase=testRail.cases().add(mycase.getSectionId(),mycase,customCaseFields).execute();
最终列表caseToAdd=newarraylist();
caseToAdd.add(mycase.getId());
run.setCaseIds(caseToAdd);
run=testRail.runs().update(run.execute();
//第一个测试开始执行
.
.
.
//第一个测试用例完成
//现在我创建了一个新的测试用例来添加
Case mySecondCase=new Case().setTitle(“测试标题”).setSuiteId(suite.getId()).setSectionId(section.getId());
mycase=testRail.cases().add(mySecondCase.getSectionId()、mySecondCase、customCaseFields).execute();
//我重复前面的步骤来添加一个新的测试用例
最终列表newCaseToAdd=newarraylist();
newCaseToAdd.add(mySecondCase.getId());
run.setCaseIds(newCaseToAdd);
run=testRail.runs().update(run.execute();

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

以下是我能找到的:

  • TestRail不支持添加/追加操作。它只支持设置/覆盖操作。这就是在同一次运行中调用setCaseID两次时发生的情况,它只保存最后一个id(这是您通常可以从
    set
    方法得到的结果)
  • 建议的解决办法是:
  • Run-activeRun=testRail.runs().get(1234.execute();
    列出testCaseIds=activeRun.getCaseIds()==null?新建ArrayList():新建ArrayList(activeRun.getCaseId());
    testCaseIds.add(333);
    testRail.runs.update(activeRun.setCaseIds(testCaseIds)).execute()

    因此,不只是设置一个新id,而是从运行中获取现有id,向其中添加id并更新运行

    资料来源:
    我解决了计划和入口结构的问题。我正在将所有测试用例保存在一个列表中,该列表作为参数传递到
    条目中。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();
    

    感谢您的回答@vladimir efimov。我不敢相信TestRail团队不支持这个功能,这是难以置信的。我认为这是基本功能。@j.barrio如果我没有错的话,testrail api java客户端不受testrail团队的支持。这只是一个开源项目。所以您实际上可以提交一个问题,请求支持这样的特性,然后提交一个包含更改的请求;)。以下是官方TR api的文档。实际上,您可以直接使用它,但必须自己实现auth+send请求。
    run = entry.getRuns().get(0);