2016-08-01 51 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(); 
      } 
     } 
    } 
} 
相关问题