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

Comments

  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.

    ReplyDelete
    Replies
    1. 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

      Delete
  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 ?

    ReplyDelete
    Replies
    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

      Delete
  3. Anonymous1/1/17

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

    Questions:
    (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

    ReplyDelete
  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" 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!

    ReplyDelete
    Replies
    1. please set proxy in ur code

      Delete

Post a Comment

Popular posts from this blog

XPATH for IE / internet explorer

All time good software testing books!

Website's underlying technology for automation