Technical Project Lead @ Huawei Technologies

My photo
Bangalore/Hyderabad, Karnataka/Andhra Pradesh, India
Have an overall 13 + yrs of experience Currently working as an Senior Architect.Expertise in design,implementation of Automation frameworks for Opensource automation tools like Selenium,Jmeter, Webdriver,Appium, Robotium Expertise in integrating Test & ALM Management tools like Rally,Qmetry,JIRA-Zephyr with Automation frameworks Expertise in design and developmenet Mobile Automation frameworks for tools like Appium, Robotium Remote Control,Cucumber BDD,Manual Testing

Followers

Saturday, March 15, 2014

How to Update Rally Test Cases and TestCase Steps

//Below code allows you to update TestCase name as well as the Test Steps associated with the Test Case

public static void getTestSteps() throws IOException, URISyntaxException,
JSONException {
String rallyURL = "https://us1.rallydev.com";
RallyRestApi restApi = new RallyRestApi(new URI(rallyURL),
"xxxx@yourcompany.com", "password");

                //Query the Test Case that you want to update
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("TC2033", "Name", "Steps")); //
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=",
"TC2033"));
QueryResponse testCaseResponse = restApi.query(testCaseRequest);
String testCaseName = "";
JsonArray jArray = testCaseResponse.getResults();
JsonObject testCase = jArray.get(0).getAsJsonObject();
testCaseName = jArray.get(0).getAsJsonObject().get("_refObjectName")
.getAsString();
System.out.println("Updating the test case with new Description ");
                      //Get the Test Case Object Refernce
String testCaseObjReference = jArray.get(0).getAsJsonObject()
.get("_ref").getAsString();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("Name", "Final test New Test Case Name");
                         //Update the test case
UpdateRequest tcUpdateRequest = new UpdateRequest(
testCaseObjReference, jsonObject);
UpdateResponse updateResponse = restApi.update(tcUpdateRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Test case Name updated successfully");
System.out.println("Now updating the test steps");
} else {
System.out.println("Failed to update Test Case Name");
}

    QueryRequest testStepRequest = new QueryRequest(
testCase.getAsJsonObject("Steps"));
testStepRequest.setFetch(new Fetch("StepIndex", "Input",
"ExpectedResult"));
JsonArray testCaseSteps = restApi.query(testStepRequest)
.getResults();
for (int j = 0; j < testCaseSteps.size(); j++) {
System.out.println(testCaseSteps.get(j).getAsJsonObject()
.get("StepIndex").getAsString()
+ ": "
+ testCaseSteps.get(j).getAsJsonObject().get("Input")
.getAsString()
+ ":"
+ testCaseSteps.get(j).getAsJsonObject()
.get("ExpectedResult").getAsString());
System.out.println(testCaseSteps.get(j).getAsJsonObject()
.get("_ref").getAsString());
String testStepRefObject = testCaseSteps.get(j)
.getAsJsonObject().get("_ref").getAsString();
JsonObject testCaseStepObject = new JsonObject();
testCaseStepObject.addProperty("Input", "NewStepThree");
UpdateRequest updateRequest = new UpdateRequest(
testStepRefObject, testCaseStepObject);
UpdateResponse upResponse = restApi.update(updateRequest);
if (upResponse.wasSuccessful()) {
System.out.println("Successfuly Updated");
} else {
System.out.println("Failed to update");
}

}
}

No comments:

Post a Comment