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 = "";
        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),

   // Query to get the id from Rally for the test case
   QueryRequest testCaseRequest = new QueryRequest("TestCase");
   testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
   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);

That's all there is!
Happy Automation...


  1. Hey Aditya,

    I 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.

    1. Yes that's right you would need the rallyrest API jar which you can find on git here

  2. Anonymous3/5/16

    Hi Aditya,

    Is this Java code, does this need to be run with an editor like the Eclipse. can this run stand alone with out any editor ?

    1. Yes that is Java code. You can still use it with any programming language you like, its just a call to the REST API

  3. Anonymous1/1/17

    Hi, I simply want to add a pdf to each test case of my Rally/CA Test Case.

    (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.


  4. Hi Aditya,
    Thanks for the code.But I am getting error in this line "QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);" as "Exception in thread "main" HTTP/1.1 401 SSO Redirection !
    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!

    1. please set proxy in ur code

  5. The information which you have provided is very good. It is very useful who is looking for selenium Online Training Bangalore


Post a Comment

Popular posts from this blog

XPATH for IE / internet explorer

RPA - Blue Prism, OpenSpan, Automation Anywhere vs UIPath