我有一个需求,需要更新特定TestCase ex的测试步骤:TC1020
我有以下代码,它返回我的TestCaseResopnse
QueryRequest testStepRequest = new QueryRequest("TestCase");
testStepRequest.setFetch(new Fetch("TC2006", "Name", "Steps")); //
testStepRequest.setQueryFilter(new QueryFilter("FormattedID", "=",
"TC2006"));
QueryResponse qresponse = restApi.query(testStepRequest);输出
{ "QueryResult":{ "_rallyAPIMajor":"2","_rallyAPIMinor":"0",“错误”:[
],
"Warnings": [
"It is no longer necessary to append \".js\" to WSAPI resources."
],
"TotalResultCount": 1,
"StartIndex": 1,
"PageSize": 200,
"Results": [
{
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"_ref": "https://us1.rallydev.com/slm/webservice/v2.0/testcase/17577048802",
"_refObjectUUID": "cd9b3b44-9f56-40fc-a486-3149479786a9",
"_objectVersion": "6",
"_refObjectName": "Emp_DataCorrectness_AllUnmatched",
"Name": "Emp_DataCorrectness_AllUnmatched",
"Steps": {
"_rallyAPIMajor": "2",
"_rallyAPIMinor": "0",
"_ref": "https://us1.rallydev.com/slm/webservice/v2.0/TestCase/17577048802/Steps",
"_type": "TestCaseStep",
"Count": 5
},
"_type": "TestCase"
}
]}}
我可以得到5的计数,这是预料中的。现在,我想获得所有测试步骤的TestCaseStep引用(例如:https://us1.rallydev.com/slm/webservice/v2.0/testcasestep/17577048860),当我复制可访问的URL浏览器时,我能够在JSON响应中看到所有5 TestStepReference。现在我想通过RestAPI来实现它。
任何帮助都是非常感谢的。
你好,基兰
发布于 2014-03-13 18:12:17
在WSAPI 2.0中,由于性能原因,不再返回对象的子集合,需要进行后续查询才能获得它们。因此,您需要执行如下操作:
JsonArray myTestCases = qresponse.getResults();
for (int i=0; i<myTestCases.size(); i++) {
JsonObject testCase = myTestCases.get(i).getAsJsonObject();
QueryRequest testStepRequest = new QueryRequest(testCase.getAsJsonObject("Steps"));
testStepRequest.setFetch(new Fetch("StepIndex", "Input", "ExpectedResult"));
JsonArray testCaseSteps = restApi.query(testStepRequest).getResults();
for (int j=0;j<testCaseSteps.size();j++){
System.out.println(
testCaseSteps.get(j).getAsJsonObject().get("StepIndex").getAsString() + ": " +
testCaseSteps.get(j).getAsJsonObject().get("Input").getAsString() + ":" + testCaseSteps.get(j).getAsJsonObject().get("ExpectedResult").getAsString());
}
}在这个答案中有一个更彻底的解释:
Migrating from Rally API 1.43 to 2.0 - Object Model
其中的示例是从一个TestCases获取一个TestSet集合,但是这个过程完全类似。
https://stackoverflow.com/questions/22377046
复制相似问题