Rally Software

  • 1.  How can I copy test cases with test steps into a different folder?

    Posted Jul 27, 2016 12:34 PM
    I want to copy a number of test cases with all their test steps from one folder into another. The UI does not make this possible but the Excel Plugin at least comes close.

    So far, I was able to export and import test cases and test steps and even put the new test case into a folder of choice. Progress!

    However, the Excel Plugin seems to be only able to work with the 'TestFolder' and 'TestCase' properties of the TestCase and TestSteps objects. Since these contain the names and not IDs, the import fails if the names are not unique - but exactly that would be highly desirable.

    I've tried to use properties like 'TestFolder.FormattedID' and 'TestCase.FormattedID' but these are not accepted by the import validator. Is there any way around this?


  • 2.  Re: How can I copy test cases with test steps into a different folder?

    Posted Jul 27, 2016 03:47 PM
    Try out these scripts - they are pretty amazing:
    https://github.com/markwilliams970?tab=repositories
    Search for "test cases" and you will find the code to do a LOT of different operations that Rally UI won't support right now.
    HTH.
    Sesh


  • 3.  Re: How can I copy test cases with test steps into a different folder?

    Posted Jul 28, 2016 03:42 AM
    I wanted to avoid coding a solution for this problem but it increasingly looks like it will be necessary... this is a good pointer in that direction. I'll wait a bit to see if anybody has a simpler solution.

    Thanks, Sesh!


  • 4.  Re: How can I copy test cases with test steps into a different folder?
    Best Answer

    Posted Aug 01, 2016 05:57 AM
    I ended up using Rally's API which seems to be the only reasonably practical way to do this. The code looked like this (C#):
     
                    // ...
                    Request folderRequest = new Request("TestFolder");
                    folderRequest.Fetch = new List<string>() { "Name", "FormattedID", "Parent" };
                    folderRequest.Query = new Query("FormattedID", Query.Operator.Equals, folder.Source);
                    //folderRequest.Workspace = workspaceRef;
                    QueryResult folderResult = restApi.Query(folderRequest);
    
                    var existingFolder = folderResult.Results.First();
                    Log("Copying from: " + existingFolder["FormattedID"] + " " + existingFolder["Name"] + " (parent: " + existingFolder["Parent"] + ")");
    
                    // get destination Folder
                    folderRequest = new Request("TestFolder");
                    folderRequest.Fetch = new List<string>() { "Name", "FormattedID", "Parent" };
                    folderRequest.Query = new Query("FormattedID", Query.Operator.Equals, folder.Destination);
                    QueryResult newFolderResult = restApi.Query(folderRequest);
    
                    var targetFolder = newFolderResult.Results.First();
                    var targetFolderRef = targetFolder["_ref"];
                    Log("Copying to: " + targetFolder["FormattedID"] + " " + targetFolder["Name"] + newFolderResult.TotalResultCount);
    
                    
                    // Get the test cases
                    Request request = new Request("TestCase");
                    request.Fetch = new List<string>() { "Name", "Description", "FormattedID", "Objective", "PreConditions", "PostConditions",
                        "ValidationInput", "ValidationExpectedResult", "Owner", "Risk", "Priority", "Type" };
                    request.Query = new Query("TestFolder.FormattedID", Query.Operator.Equals, folder.Source);
                    QueryResult queryResult = restApi.Query(request);
    
                    if (queryResult.TotalResultCount == 0)
                    {
                        Log("Did not find any test case!");
                        return;
                    }
    
                    foreach (var sourceTC in queryResult.Results)
                    {
                        Log("TC: " + sourceTC["FormattedID"] + " Name: " + sourceTC["Name"]); // + " Description: " + result["Description"]);
    
                        // Create a new Test Case
                        DynamicJsonObject targetTC = new DynamicJsonObject();
                        targetTC["Name"] = sourceTC["Name"];
    
                        // Populate field data from Source to Target
                        targetTC["Name"] = sourceTC["Name"];
                        targetTC["Description"] = sourceTC["Description"];
                        targetTC["Owner"] = sourceTC["Owner"];
                        targetTC["Objective"] = sourceTC["Objective"];
                        targetTC["Type"] = sourceTC["Type"];
                        targetTC["Risk"] = sourceTC["Risk"];
                        targetTC["Priority"] = sourceTC["Priority"];
                        targetTC["PostConditions"] = sourceTC["PostConditions"];
                        targetTC["PreConditions"] = sourceTC["PreConditions"];
                        targetTC["ValidationInput"] = sourceTC["ValidationInput"];
                        targetTC["ValidationExpectedResult"] = sourceTC["ValidationExpectedResult"];
                        targetTC["TestFolder"] = targetFolderRef;
    
                        CreateResult createResult = restApi.Create("TestCase", targetTC);
    
                        // Get the item to make sure it was created
                        DynamicJsonObject item = restApi.GetByReference(createResult.Reference);
                        Log("TC was created: " + item.Fields.ToString());
    
                        // Get existing test steps and copy
                        Request stepRequest = new Request("TestCaseStep");
                        stepRequest.Fetch = new List<string>() { "TestCase", "StepIndex", "Input", "ExpectedResult" };
                        stepRequest.Query = new Query("TestCase.FormattedID", Query.Operator.Equals, sourceTC["FormattedID"]);
                        QueryResult stepsResult = restApi.Query(stepRequest);
                        foreach(var step in stepsResult.Results)
                        {
                            Log(step["StepIndex"] + ": " +
                                step["Input"] + ":" + step["ExpectedResult"]);
    
                            DynamicJsonObject targetStep = new DynamicJsonObject();
                            targetStep["StepIndex"] = step["StepIndex"];
                            targetStep["Input"] = step["Input"];
                            targetStep["ExpectedResult"] = step["ExpectedResult"];
                            targetStep["TestCase"] = createResult.Reference;
    
                            CreateResult createStep = restApi.Create("TestCaseStep", targetStep);
                        }
    
                    }