2014-03-13 14 views
0

我有一個要求,我需要更新teststeps特定的TestCase例如:TC1020如何獲得拉力TestCaseStepReferences爲特定的TestCase

我有下面的代碼返回我的TestCaseResopnse

 QueryRequest testStepRequest = new QueryRequest("TestCase"); 
     testStepRequest.setFetch(new Fetch("TC2006", "Name", "Steps")); // 
     testStepRequest.setQueryFilter(new QueryFilter("FormattedID", "=", 
       "TC2006")); 
     QueryResponse qresponse = restApi.query(testStepRequest); 

OUTPUT

{ 「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,其被期待。現在我想獲得所有teststep的TestCaseStep參考(例如:https://us1.rallydev.com/slm/webservice/v2.0/testcasestep/17577048860) 當我複製URL瀏覽器時,我能夠在JSON響應中看到全部5個TestStepReference。現在我想從RestAPI中實現它。

任何幫助,高度讚賞

問候, 基蘭

回答

0

在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

凡例子是從獲得的TestCase的集合一個TestSet,但是這個過程是完全相似的。

+0

非常感謝Mark。有效 – kiran