How do you update the results of a test run into Rally ? Rally REST API
If you are looking for code that can help you update results into Rally after an automated test run, here is the code:
String host = "https://rally1.rallydev.com";
String username = configProp.getProperty("RallyUserName");
String password = configProp.getProperty("RallyPassword");
String wsapiVersion = "v2.0";
String workspaceRef = "/workspace/11111";
String applicationName = "Rest_FindTC";
RallyTestCaseId = TCID;
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
// Query to get the id from Rally for the test case
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", TCID));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
//Add a Test Case Result
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
java.util.Date date= new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String timestamp = sdf.format(date);
newTestCaseResult.addProperty("Date", timestamp);
newTestCaseResult.addProperty("Build", Build);
newTestCaseResult.addProperty("Notes", "Selenium Automated Test Run");
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
restApi.close();
That's all there is!
Happy Automation...
String host = "https://rally1.rallydev.com";
String username = configProp.getProperty("RallyUserName");
String password = configProp.getProperty("RallyPassword");
String wsapiVersion = "v2.0";
String workspaceRef = "/workspace/11111";
String applicationName = "Rest_FindTC";
RallyTestCaseId = TCID;
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
// Query to get the id from Rally for the test case
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", TCID));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
//Add a Test Case Result
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
java.util.Date date= new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String timestamp = sdf.format(date);
newTestCaseResult.addProperty("Date", timestamp);
newTestCaseResult.addProperty("Build", Build);
newTestCaseResult.addProperty("Notes", "Selenium Automated Test Run");
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
restApi.close();
That's all there is!
Happy Automation...
Hey Aditya,
ReplyDeleteI wanted to use your code for rally connection so that I can update my results automatically in rally. Is there any jar file i have to put in my project to run your code? (like rallytoolkitforselenium project which is available on git?)
Your prompt response shall be appreciated.
Yes that's right you would need the rallyrest API jar which you can find on git here https://github.com/RallyTools/RallyRestToolkitForJava/wiki/User-Guide#setup
DeleteHi Aditya,
ReplyDeleteIs this Java code, does this need to be run with an editor like the Eclipse. can this run stand alone with out any editor ?
Yes that is Java code. You can still use it with any programming language you like, its just a call to the REST API
DeleteI see errors at new URI(host) as cannot convert from uri to rallymanager
DeleteQueryRequest, JSONObject, CreateRequest, CreateResponse... : which namespace I should import
RallyRestApi restApi = new RallyRestApi( new URI(host), username, password);
Deletethis constructor has been deprecated. use below constructor
RallyRestApi restApi = new RallyRestApi(new URI(host), API_KEY);
Hi, I simply want to add a pdf to each test case of my Rally/CA Test Case.
ReplyDeleteQuestions:
(1) Is this REST API still valid as of 12/31/2016?
(2) Does this work with the community edition?
(3) Are there Maven references available for the Java classes used?
I am building a pdf that would be created from TestNG/Selenium while executing the test steps. Each result (passed/failed) would have an image with test case/step# posted to the pdf in a tabular format.
MS
Hi Aditya,
ReplyDeleteThanks for the code.But I am getting error in this line "QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);" as "Exception in thread "main" java.io.IOException: HTTP/1.1 401 SSO Redirection !
at com.rallydev.rest.RallyRestApi.doRequest(RallyRestApi.java:258)
at com.rallydev.rest.RallyRestApi.doGet(RallyRestApi.java:323)
at com.rallydev.rest.RallyRestApi.query(RallyRestApi.java:179)
at com.comcast.sik.rally.updateRally.main(updateRally.java:49)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [util.c:840]"
Can you please help me out? Thanks a lot in advance!
please set proxy in ur code
DeleteHow do add tester and testset value ? not able to find the solution?
ReplyDeleteHi Aditya,
ReplyDeleteI want to update the result of the test case inside a test set. With your code i am able to update the result of a test case but not inside a test set. Can you help me in finding the solution on how to update the result of test case of a test set?
Hi, I need to delete all result set from a test case. Could you pls help.
ReplyDeletehow to update test reports in rally ?
ReplyDeletehermes belt
ReplyDeleteadidas tubular shadow
ferragamo belts
air max 2018
nike air vapormax
coach outlet store online
longchamp
christian louboutin outlet
louboutin shoes uk
off white shoes
I am looking for CSHARP code to update the automation status in rally...could someone please help me?
ReplyDeleteyeezy 380
ReplyDeletekyrie 7 shoes
curry 6 shoes
yeezys
balenciaga shoes
supreme clothing
retro jordans
yeezy shoes
supreme hoodie
golden goose sneakers