2016-08-01 53 views
0

我試圖將測試用例作爲json對象。它將測試文件夾信息作爲一個URI。我怎樣才能得到該測試文件夾的名稱,而無需再次點擊此uri。我有一個拉力賽的測試案例。我想使用java API獲取測試用例存在的測試文件夾的名稱

當我打的URI它給我的TFxxx,這是我需要直接..

我試圖得到儘可能jsonObj.get("TestFolder.Name").toString();簡單地返回null。

任何幫助?

+0

'jsonObj.getString(「TestFolder.Name」)'? – Manu

+0

as'jsonObj.getString(「TestFolder.Name」)'爲null,它賦予'jsonObj.getString(「TestFolder.Name」)。toString()'也爲null –

回答

1

在下面我查詢恰好是在TestFolder一個TestCase,然後遍歷文件夾這樣的代碼:

testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name") 

這裏是返回TestFolder的名字一個完整的例子:

public class GetTestFolder { 

    public static void main(String[] args) throws Exception { 

     String host = "https://rally1.rallydev.com"; 
     String applicationName = "Example: get Folder of TestCase"; 
     String projectRef = "/project/12352608219"; 
     String apiKey = "_abc123"; 
     RallyRestApi restApi = null; 
     try { 
      restApi = new RallyRestApi(new URI(host),apiKey); 
      restApi.setApplicationName(applicationName); 
      QueryRequest testCaseRequest = new QueryRequest("TestCase"); 
      testCaseRequest.setProject(projectRef); 

      testCaseRequest.setFetch(new Fetch(new String[] {"FormattedID","Name","TestFolder"})); 
      testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC47")); 
      testCaseRequest.setScopedDown(false); 
      testCaseRequest.setScopedUp(false); 

      QueryResponse testCaseResponse = restApi.query(testCaseRequest); 
      System.out.println("Successful: " + testCaseResponse.wasSuccessful()); 
      for (int i=0; i<testCaseResponse.getResults().size();i++){ 
       JsonObject testCaseJsonObject = testCaseResponse.getResults().get(i).getAsJsonObject(); 
       System.out.println("Name: " + testCaseJsonObject.get("Name") + " FormattedID: " + testCaseJsonObject.get("FormattedID") + " TestFolder: " + testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name")); 

      } 
     } finally { 
      if (restApi != null) { 
       restApi.close(); 
      } 
     } 
    } 
} 
相關問題