Saturday, March 15, 2014

How to get the List of all Test Cases

//Below Code fetches the list of TestCases based on Filter (Project,Folder,Owner..)

public List<String> getTestCaseDetails(RallyRestApi restApi,
String methodName, String folder, String projectName)
throws IOException {
// All Test cases
QueryRequest testcases = new QueryRequest("Test Case");
testcases.setFetch(new Fetch("FormattedID", "Name", "Owner",
"Test Folder"));
testcases.setQueryFilter(new QueryFilter("Project.Name", "=",
projectName).and(
new QueryFilter("TestFolder.Name", "=", folder)).and(
new QueryFilter("Method", "=", methodName)));
testcases.setOrder("FormattedID ASC");
QueryResponse queryResponse = restApi.query(testcases);
JsonArray testCaseList = new JsonArray();
if (queryResponse.wasSuccessful()) {
System.out.println(String.format("\nTotal results: %d",
queryResponse.getTotalResultCount()));

testCaseList = queryResponse.getResults().getAsJsonArray();
for (JsonElement testCase : testCaseList) {
JsonObject json = new JsonObject();
json = testCase.getAsJsonObject();
System.out.println(json.get("FormattedID"));
System.out.println(json.get("LastVerdict"));
System.out.println(testCase);
testCaseInfoList.add(testCase.toString());
}
} else {
for (String err : queryResponse.getErrors()) {
System.err.println("\t" + err);
}
}
return testCaseInfoList;
}

No comments:

Post a Comment