Though i am able to pull all the test cases present in a particular test set and modify or update all the test Results.
Test set is not reflecting the verdict(pass/fail) after updating the Test cases in that Test set.
If i navigate to one of the tescase detail page, i am able to see updated testcase result
This is the test-set status after updating the testcases
But when one of those testcases are opened i am able to see the updated testcase result
code:
QueryRequest testSetRequest = new QueryRequest("TestSet");
testSetRequest.setFetch(new Fetch(new String[] {"Name", "TestCases", "FormattedID"}));
testSetRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TS346"));
QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
if(testSetQueryResponse.wasSuccessful()){
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").getAsJsonObject().get("_ref"));
int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonObject().get("Count").getAsInt();
System.out.println(numberOfTestCases);
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());
String s= testCases.get(j).getAsJsonObject().get("FormattedID").getAsString();
testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", s));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
try{
//Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Date", "2013-11-29T18:00:00.000Z");
newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
newTestCaseResult.addProperty("Build", "208");
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if(createResponse.wasSuccessful()){
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read Test Case
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Test Case Result %s...", ref));
GetRequest getRequest = new GetRequest(ref);
getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
System.out.println(String.format("Read Test Case Result. Date = %s, Verdict = %s", obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for ( i=0; i<createErrors.length;i++) {
System.out.println(createErrors[i]);
}
}
}
finally{
}
}
}
}
}
else {
String[] createErrors;
createErrors = testSetQueryResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for (int i=0; i<createErrors.length;i++) {
System.out.println(createErrors[i]);
}
}
so,Any idea of how to update the test set results
Just need to add the below code at the new test case result
newTestCaseResult.addProperty("TestSet", testsetref);
Related
I have built a Rally dependency, which auto creates test case, folder in Test Plan. While creating test case it checks first if there any any existing test case with same name, else it creates new test case.
This was working while total test case size was small, while the test case size increased, i am seeing duplicate test cases are created. So I made thread to wait for few seconds (Thread.sleep(8000)) after checking existing scenarios and then creating new scenario. It works by this way.
Is there better way to handle & implement this to handle any size of test case. Please advice.
String tcName = rallyMethods.getTestScenarios(parentFolder, scenarioName);
Thread.sleep(8000);
if (tcName == null) {
rallyMethods.createTestCase(parentFolder, scenarioName);
Thread.sleep(8000);
} else {
rallyMethods.updateTestCase(parentFolder, scenarioName);
Thread.sleep(8000);
}
public String getTestScenarios(String parentFolderName, String ScenarioName) throws Throwable {
String sName = null;
String pFolder;
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setLimit(Integer.MAX_VALUE);
testCaseRequest.setPageSize(Integer.MAX_VALUE);
testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "Workspace", "Project", "TestFolder"));
testCaseRequest.setQueryFilter(new QueryFilter("Name", "=", ScenarioName));
testCaseRequest.setWorkspace(WORKSPACE_ID);
testCaseRequest.setProject(PROJECT_ID);
QueryResponse testCaseQueryResponse = query(testCaseRequest);
int testCaseCount = testCaseQueryResponse.getTotalResultCount();
// System.out.println("TestCaseCount:" + testCaseCount);
for (int i = 0; i < testCaseCount; i++) {
JsonObject scenarioObj = testCaseQueryResponse.getResults().get(i).getAsJsonObject();
String scenarioName = String.valueOf(scenarioObj.get("Name").getAsString());
JsonElement pFolderObj = scenarioObj.get("TestFolder");
if (!(pFolderObj.isJsonNull())) {
JsonObject tFolderObj = scenarioObj.get("TestFolder").getAsJsonObject();
pFolder = String.valueOf(tFolderObj.get("Name").getAsString());
if (parentFolderName.equalsIgnoreCase(pFolder)) {
sName = scenarioName;
logger.info("Test Scenarios identified in Rally: " + sName);
} else {
logger.info("Scenario, " + ScenarioName + " not found, New Scenario will be created in Rally");
}
}
}
return sName;
}
public void createTestCase(String parentFolderName, String testCaseName) throws Throwable {
String tcName = null;
String userID = readUser();
// Query Child Folders:
QueryRequest testFolderRequest = new QueryRequest("TestFolder");
testFolderRequest.setFetch(new Fetch("Name", "Workspace", "Project"));
testFolderRequest.setQueryFilter(new QueryFilter("Name", "=", parentFolderName));
testFolderRequest.setWorkspace(WORKSPACE_ID);
testFolderRequest.setProject(PROJECT_ID);
QueryResponse testFolderQueryResponse = query(testFolderRequest);
int folderCount = testFolderQueryResponse.getTotalResultCount();
for (int i = 0; i < folderCount; i++) {
String testFolderRef = testFolderQueryResponse.getResults().get(i).getAsJsonObject().get("_ref").getAsString();
JsonObject testFolderObj = testFolderQueryResponse.getResults().get(i).getAsJsonObject();
String pFolder = String.valueOf(testFolderObj.get("Name").getAsString());
if (pFolder.equalsIgnoreCase(parentFolderName)) {
//System.out.println("Creating a test case...");
JsonObject newTC = new JsonObject();
newTC.addProperty("Name", testCaseName);
newTC.addProperty("Workspace", WORKSPACE_ID);
newTC.addProperty("Project", PROJECT_ID);
newTC.addProperty("Description", "Selenium Automated TestCase");
newTC.addProperty("TestFolder", testFolderRef);
newTC.addProperty("Method", "Automated");
newTC.addProperty("Type", "Functional");
if (!(userID == null)) {
newTC.addProperty("Owner", userID);
}
CreateRequest createRequest = new CreateRequest("testcase", newTC);
CreateResponse createResponse = create(createRequest);
if (createResponse.wasSuccessful()) {
JsonObject tcObj = createResponse.getObject();
tcName = String.valueOf(tcObj.get("Name").getAsString());
logger.info("Created test scenario name is: " + tcName);
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
logger.info("Error while creating test scenario below parent folder!");
for (int j = 0; j < createErrors.length; j++) {
System.out.println(createErrors[j]);
logger.info(createErrors[j]);
}
}
}
}
}
Hmmm... I'm not too familiar with the Java REST toolkit, but I can't think of a reason why a larger set of test cases in the workspace would cause the query to fail like that.
Did you try checking testCaseQueryResponse.wasSuccessful()? If it returns false, can you see what the error is? testCaseQueryResponse.getErrors()
My first thoughts are that you should provide a reasonable value for the limit and pageSize parameters, rather than passing Integer.MAX_VALUE. And second, rather than checking if the returned test cases are in the specified parent folder, you should include a query filter to filter the test cases results on TestFolder.Name = parentFolderName. Then you should only be expecting either 1 or 0 results returned (assuming that you're expecting all test cases within a test folder to have unique names).
I tried getting the test case as json object. It will have Test folder information as a uri. How can I get the name of that test folder without hitting this uri again.
When I hit the URI it gives me the TFxxx, This is what I need directly..
I tried getting as jsonObj.get("TestFolder.Name").toString(); which simply returns null.
Any help?
In the code below I query for a TestCase that happens to be in a TestFolder, and then traverse to the folder like this:
testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name")
Here is a full example that returns TestFolder's name:
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();
}
}
}
}
How do I fetch child user stories with Java client using Rally API?
Using Chrome's Postman client with URL https://us1.rallydev.com/slm/webservice/v2.0/HierarchicalRequirement/ObjectId/Children, I am able to fetch the children user stories.
But when I try with a Java client, like this:
QueryRequest request = new QueryRequest("/HierarchicalRequirement/ObjectId/Children");
it doesn't work.
Any pointer would be helpful.
It will take fetching "Children" collection on user stories and then hydrating it in a separate request. Here is an example based on latest version of Rally toolkit for Java:
public class GetChildStories {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123";
String applicationName = "Find Child Stories of Epics filtered by Tag";
String workspaceRef = "/workspace/12352608129";
RallyRestApi restApi = null;
try {
restApi = new RallyRestApi(new URI(host),apiKey);
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setWorkspace(workspaceRef);
restApi.setApplicationName(applicationName);
storyRequest.setFetch(new Fetch(new String[] {"Name", "FormattedID", "Tags", "Children"}));
storyRequest.setLimit(1000);
storyRequest.setScopedDown(false);
storyRequest.setScopedUp(false);
storyRequest.setQueryFilter((new QueryFilter("Tags.Name", "contains", "\"tag1\"")).and(new QueryFilter("DirectChildrenCount", ">", "0")));
QueryResponse storyQueryResponse = restApi.query(storyRequest);
System.out.println("Successful: " + storyQueryResponse.wasSuccessful());
System.out.println("Size: " + storyQueryResponse.getTotalResultCount());
for (int i=0; i<storyQueryResponse.getTotalResultCount();i++){
JsonObject storyJsonObject = storyQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + storyJsonObject.get("Name") + " FormattedID: " + storyJsonObject.get("FormattedID"));
QueryRequest childrenRequest = new QueryRequest(storyJsonObject.getAsJsonObject("Children"));
childrenRequest.setFetch(new Fetch("Name","FormattedID"));
int numberOfChildren = storyJsonObject.get("DirectChildrenCount").getAsInt();
System.out.println(numberOfChildren);
//load the collection
JsonArray children = restApi.query(childrenRequest).getResults();
for (int j=0;j<numberOfChildren;j++){
System.out.println("Name: " + children.get(j).getAsJsonObject().get("Name") + children.get(j).getAsJsonObject().get("FormattedID").getAsString());
System.out.println("Name: " + children.get(0).getAsJsonObject().get("Name") + children.get(0).getAsJsonObject().get("FormattedID").getAsString());
}
}
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}
I am trying to access and modify test cases in HP QC by JAVA. The code is running successfully but the Step, status, Exec dates are not being updated.
Here is my code
for (Com4jObject obj : testInstances)
{
ITSTest testInstance = obj.queryInterface(ITSTest.class);
ITSTest tstest = obj.queryInterface(ITSTest.class);
IRunFactory runfactory = tstest.runFactory().queryInterface(IRunFactory.class);
IRun run=runfactory.addItem("RunNew").queryInterface(IRun.class);
Com4jObject step = run.stepFactory();
// run.field("Step #", "Step1");
run.status("Passed");
// Com4jObject steps = run.stepFactory();
// System.out.println(run.field("Actual Result"));
// run.field("Actual Result", "As Expected. Please find attachment with TC001");
if(tstest.name().contains("[1]TC001"))
{
try {
String fileName = new File(files.get(i)).getName();
String folderName = new File(files.get(i)).getParent();
System.out.println("FILE: "+fileName);
System.out.println("FOLDER: "+folderName);
IAttachmentFactory attachfac = tstest.attachments().queryInterface(IAttachmentFactory.class);
IAttachment attach = attachfac.addItem(fileName).queryInterface(IAttachment.class);
IExtendedStorage extAttach = attach.attachmentStorage().queryInterface(IExtendedStorage.class);
extAttach.clientPath(folderName);
extAttach.save(fileName, true);
//attach.description(Actual);
attach.post();
attach.refresh();
} catch(Exception e) {
System.out.println("QC Exceptione : "+e.getMessage());
}
}
run.post();
//AppLog.info(" Test Instance: %s", testInstance.name());
System.out.println(("Test Instance: %s"+ testInstance.name()));
}
You need to call post() on each item separately: Test run and each created step.
Example in C# starting from the point where you retrieve the step factory.
// Create test run
var oRunInstance = (QcClient.RunFactory)oTsTest.RunFactory;
var oRun = (QcClient.Run)oRunInstance.AddItem("Performance Test");
oRun.Status = "Passed";
oRun.Post();
oRun.Refresh();
// Create test run steps
var oTest = (QcClient.Test)oTsTest.Test;
var tsDesignStepList = oTest.DesignStepFactory.NewList("");
var oStepFactory = (QcClient.StepFactory)oRun.StepFactory;
foreach (QcClient.DesignStep oDesignStep in tsDesignStepList)
{
var oStep = (QcClient.Step)oStepFactory.AddItem(oDesignStep.StepName);
oStep.Status = "Passed";
oStep.Post();
}
When I request "TestSet" query to fetch TestCases in a specific test set.
But, the fetched TestCases contains the full list of test cases in the project not in the specific test set.
QueryRequest queryTestSet = new QueryRequest("TestSet");
queryTestSet.setFetch(new Fetch("Name", "Project", "TestCases"));
queryTestSet.setQueryFilter(new QueryFilter("name", "=", "TestSet_Name"));
QueryResponse responseTestSet = RallyRestAPI.getAPI().query(queryTestSet);
JsonArray testcasesJson = responseTestSet.getResults().get(0).getAsJsonObject().getAsJsonArray("TestCases");
For example, there are total 500 test cases in the project
I added test cases and results of "Automated" test cases in a TestSet (300 test cases)
Then, I request the query above, the size of "testcasesJson" returns 500 and it includes full list of test cases.
How can I read the test cases that only added in a TestSet?
Rally Rest JAR Version: rally-rest-api-1.0.7.jar
This code example that uses 2.0.4 jar returned only test cases associated with a test set:
public class GetTCofTS {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String username = "user#co.com";
String password = "secret";
String applicationName = "RESTExampleFindTestCasesOfTestSet";
String workspaceRef = "/workspace/1111";
String projectRef = "/project/2222";
String wsapiVersion = "1.43";
RallyRestApi restApi = null;
try {
restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setApplicationName(applicationName);
QueryRequest testSetRequest = new QueryRequest("TestSet");
testSetRequest.setWorkspace(workspaceRef);
restApi.setWsapiVersion(wsapiVersion);
testSetRequest.setFetch(new Fetch(new String[] {"Name", "TestCases", "FormattedID"}));
testSetRequest.setQueryFilter(new QueryFilter("Name", "=", "someTS"));
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"));
int numberOfTestCases = testSetJsonObject.get("TestCases").getAsJsonArray().size();
System.out.println(numberOfTestCases);
if(numberOfTestCases>0){
for (int j=0;j<numberOfTestCases;j++){
System.out.println(testSetJsonObject.get("TestCases").getAsJsonArray().get(j).getAsJsonObject().get("FormattedID"));
}
}
}
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}