Rally Software

  • 1.  In Rally, Using Java REST API, How to get the complete list of test cases present in all sub-folders of a TestPlan folder?

    Posted Jul 05, 2018 03:40 AM

    In query filter, i have tried with FormattedID, TestFolder.Parent.Name, TestFolder.Name. But could not get the test cases of all sub folders.

    Here TestFolderID can be a TestPlan folder name OR any parent folder with subfolders.

    With below code, I am getting only the test cases directly present in the folder, but not from all subfolders of a given folder name. 

                

    TestFolderID="TF27980";   
    QueryRequest queryRequest = new QueryRequest("TestCases");            
    queryRequest.setFetch(new Fetch(new String[] {"Name", "TestCases","FormattedID","TestFolder"}));             
    queryRequest.setWorkspace(workspaceRef.get());            
    queryRequest.setQueryFilter(new QueryFilter("TestFolder.Parent.Name", "=",  TestFolderID) );             
    queryRequest.setScopedDown(true);            
    queryRequest.setLimit(Integer.MAX_VALUE);            
    queryRequest.setPageSize(Integer.MAX_VALUE);             
    QueryResponse queryResponse = null;            
    JsonArray jsonarr = new JsonArray();            
    queryResponse = restApi.get().query(queryRequest);            
    int responseTotalResultsCount = queryResponse.getTotalResultCount


  • 2.  Re: In Rally, Using Java REST API, How to get the complete list of test cases present in all sub-folders of a TestPlan folder?

    Posted Jul 05, 2018 05:40 AM

    Madhusudhan,

     

    You can do what is mentioned in this Stackoverflow post, Rally: Java: I have few test folders inside a test folder and all folders have test cases. How to get all the test cases… 

     

    Add another parameter to your query to get the children and the grand children.

     

    QueryFilter children = new QueryFilter("TestFolder.Name", "=", "TestFolderParent1");
    QueryFilter grandChildren = new QueryFilter("TestFolder.Parent.Name", "=", "TestFolderParent1");
    testSetRequest.setQueryFilter(children.Or(grandChildren));

    This will only work if the hierarchy looks like this, however:

    TestFolderParent1
         testcase1, testcase2..... testcase5
         TestFolderChild1
               testcase10, testcase11..... testcase15
              TestFolderChild2
               testcase20, testcase21..... testcase25

    If it is any deeper, it could get pretty messy pretty quick with adding OR statements.

     

    If you don't know for sure how deep the Test Folder Hierarchy is, I believe the only way to do it would be to start from the top Test Folder and then retrieve Test Cases and then the child Test Folders to retrieve the Test Cases and child Test Folders in them until you reach a leaf Test Folder and then get those Test Cases.

     

    Hope that helps.

     

    Michael



  • 3.  Re: In Rally, Using Java REST API, How to get the complete list of test cases present in all sub-folders of a TestPlan folder?

    Posted Jul 06, 2018 12:23 AM

    Thanks Michael for the reply. I tried the filter you mentioned, but the result  count is 0.

    Test Folder 1 -> Test Folder 2 -> Test Folder 3 -> test case1, 2,3

    I tried with Parent folder as Test Folder1. Also tried with Test Folder 2. But the result count in both cases is 0.

    I expected the Test Folder 1 to give atleast the Test Folder 2, so that i can query for Test Folder 2 and so on in a loop.



  • 4.  Re: In Rally, Using Java REST API, How to get the complete list of test cases present in all sub-folders of a TestPlan folder?

    Broadcom Employee
    Posted Jul 06, 2018 11:45 AM

    Hi Madhusudhan,

    Can you include your complete code (perhaps attach to this thread) after making the suggested changes by Michael?

     

    Thanks,

    Sagi



  • 5.  Re: In Rally, Using Java REST API, How to get the complete list of test cases present in all sub-folders of a TestPlan folder?

    Posted Jul 09, 2018 11:57 AM

    Sagi, Sorry for late response. Here is the code:

     

    package com.qa.framework.executor.test;

     

    import java.net.URI;

     

    import com.google.gson.JsonArray;

    import com.google.gson.JsonObject;

    import com.rallydev.rest.RallyRestApi;

    import com.rallydev.rest.request.QueryRequest;

    import com.rallydev.rest.response.QueryResponse;

    import com.rallydev.rest.util.Fetch;

    import com.rallydev.rest.util.QueryFilter;

     

    public class GetTCofTF {

     

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

     

    String host = "https://rally1.rallydev.com";

     

    String applicationName = "RESTExampleFindTestCasesOfTestSet";

    String workspaceRef = "/workspace/25194919975";

    String projectRef = "/project/58270664632";

    String wsapiVersion = "v2.0";

     

     

    RallyRestApi restApi = null;

    try {

    if (null == restApi || null == restApi) {

    restApi=new RallyRestApi(

    new URI(host),

    "<RALLY KEY>");

     

    restApi.setApplicationName(applicationName);

     

    QueryRequest testSetRequest = new QueryRequest("TestCases");

     

    testSetRequest.setWorkspace(workspaceRef);

    restApi.setWsapiVersion(wsapiVersion);

    testSetRequest.setFetch(new Fetch(new String[] {"Name","FormattedID"}));

     

    // testSetRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TS5169"));

     

    //Query for test cases present in the Test Plan folder

    QueryFilter children = new QueryFilter("TestFolder.Name", "=", "TF17980");

    QueryFilter grandChildren = new QueryFilter("TestFolder.Parent.Name", "=", "TF17980");

    testSetRequest.setQueryFilter(children.or(grandChildren));

     

     

    QueryResponse testSetQueryResponse = restApi.query(testSetRequest);

    System.out.println("Successful: " + testSetQueryResponse.wasSuccessful());

    System.out.println("Size: " + testSetQueryResponse.getTotalResultCount());

    for (int i=0; i<testSetQueryResponse.getResults().size();i++){

    JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(i).getAsJsonObject();

    System.out.println("Name: " + testSetJsonObject.get("Name") + " ref: " + testSetJsonObject.get("_ref").getAsString() + " Test Cases: " + testSetJsonObject.get("TestCases"));

    //TestCases is an object with a Count and a ref to load the collection

    int numberOfTestCases = testSetJsonObject.getAsJsonObject("TestCases").get("Count").getAsInt();

     

    if(numberOfTestCases > 0) {

        QueryRequest testCaseRequest = new QueryRequest(testSetJsonObject.getAsJsonObject("TestCases"));

        testCaseRequest.setFetch(new Fetch("FormattedID"));

        //load the collection

        JsonArray testCases = restApi.query(testCaseRequest).getResults();

        for (int j=0;j<numberOfTestCases;j++){

            System.out.println(testCases.get(j).getAsJsonObject().get("FormattedID").getAsString());

        }

    }

     

    }

    }

    } catch (Exception e){

    e.printStackTrace();

    } finally {

    if (restApi != null) {

    restApi.close();

    }

    }

    }

    }



  • 6.  Re: In Rally, Using Java REST API, How to get the complete list of test cases present in all sub-folders of a TestPlan folder?

    Posted Jul 25, 2018 06:31 AM

    Madhusudhan,

     

    I am not sure if you were able to figure this out.  But, again, you will need to add as many queries for the levels you have in your hierarchy.  So if what you posted above is the hierarchy, then something like this needs to be done.

     

    Also, as mentioned in that Stackoverflow Post, this can get pretty unwieldy if you have a deep hierarchy.  I didn't test this to ensure there weren't any parentheses errors, but it should be something like this:

     

    QueryFilter children = new QueryFilter("TestFolder.Name", "=", "TestFolderParent1");
    QueryFilter grandChildren = new QueryFilter("TestFolder.Parent.Name", "=", "TestFolderParent1");
    QueryFilter greatGrandChildren = new QueryFilter("TestFolder.Parent.Parent.Name", "=", "TestFolderParent1");
    testSetRequest.setQueryFilter((children.Or(grandChildren)).Or(greatGrandChildren));