Update Execution Status of a test instance in ALM using REST API

It has been seen, that a large number of IT companies use ALM as a test case management tool and also use Selenium for Automation testing.

Companies have requirement of updating the test case execution status in ALM from within the automation scripts.

One way of achieving this is by using OTAClient.dll and COM4J. But there are certain restrictions when using it i.e 

  • You have to use 32bit JDK
  • When we are talking about dlls then it means, this approach is Platform dependent.


So, the other way to achieve ALM integration with any automation testing tool is by using REST API.

Below mentioned are the REST endpoints to access the test cases and updated their status in ALM :

Pre-requisites to hit the api endpoints (If using POSTMAN, Please enable the interceptor):

a. There should be a defined directory structure in ALM. I am following the following hierarchy :

Parent Folder -> TestSetFolder -> TestSet -> TestInstances



b. User Authentication using basic authentication{base64 encoding} (username=abcxyz and password=xyzabc):

POST  http://{url}:{port}/qcbin/api/authentication/sign-in  (e.g  {url} = companyName.alm.com, {port} = 8080)
this would provide the cookies required to perform further actions.

Cookies generated and required are as follows :
  1.     ALM_USER
  2.     LWSSO_COOKIE_KEY
  3.     QCSession
  4.     XSRF-TOKEN



Note :
In the below mentioned endpoints, a few variable names are being used i.e just to make it easy to understand that the result of a GET request is the input to the subsequent GET/PUT request (variable names have been formatted as BOLD in the below mentioned documentation to keep their denotion understandable as vars and parameters in subsequent requests).
Don't use these variables anywhere while testing these endpoints . These are just used for the better understanding.




API Endpoints required to work with test instances :

1. To get the Parent folder id :

var parentFolderId =
GET  http://{url}:{port}/qcbin/rest/domains/PRODUCTION/projects/Product/test-set-folders?query={name[nameOfParentFolder];parent-id[0]}&fields=id,name

2. To get a test set folder id (Assumption, we know the test set folder name and the parent folder id {This has to be decided as its a prerequisite to get started})

var testSetFolderId =
GET  http://{url}:{port}/qcbin/rest/domains/PRODUCTION/projects/Product/test-set-folders?query={name[nameOfTestSetFolder];parent-id[parentFolderId]}&fields=id,name

3. To get the test set id :

var testSetId =
GET  http://{url}:{port}/qcbin/rest/domains/PRODUCTION/projects/Product/test-sets?query={name[nameOfTestSet];test-set-folder.id[testSetFolderId]}&fields=id,name

4. To get the testInstanceId/testcycl-id :

var testInstanceId =
GET http://{url}:{port}/qcbin/rest/domains/PRODUCTION/projects/Product/test-instances?query={cycle-id[testSetId];test-id[testId]}&fields=id,name,test-config-id

5. Change the status of the testInstance in testLab under execution grid :

PUT  http://{url}:{port}/qcbin/rest/domains/PRODUCTION/projects/Product/test-instances/ testInstanceId
with body in json format as follows :

{
  "Fields": [  {
"Name": "status",
 "values": [      
{
"value": "Passed"     
}
}, 
{  
"Name": "subtype-id",   
"values": [
{
"value": "hp.qc.test-instance.EXTERNAL-TEST"     
}
}
]
}

6. User sign-out :

GET  http://{url}:{port}/qcbin/api/authentication/sign-out

 {This will remove all the cookies generated during sign-in and logs-off the user and ends the session}

You can use the above mentioned endpoints to update test case execution status via your scripts as well. Use REST ASSURED for this.

Comments

  1. Good job.. Thanks for sharing

    ReplyDelete
  2. Nice article.. thanks fr sharing..

    ReplyDelete
  3. Hi Mukul, This could be a more informative post if...

    1. You could define in a problem / solution format, in the sense that more concrete state definition of...

    1. You automation framework boundary interfacing with ALM.
    2. Connector blocks and execution block where this code actually runs? An abstract pictorial representation would do a great job in helping blog reader visualizing the flow.
    3. What if a defined directory structure is not there? Is it a MUST or only a Should condition?
    4. Why ALM or your automation framework isn't already supporting this feature?

    ReplyDelete
  4. Thanks, for sharing.
    I'd like to find all Tests (in test plan) which are linked to a test-instance (in Test lab)
    any Idea how to do ?
    thanks

    ReplyDelete
  5. Can We go to each step in test case and update the status for each steps

    ReplyDelete
  6. Hi, thanks for the post. I have a requirement to create a folder in Test Lab and sub folders in that. Can you provide the API for that.

    ReplyDelete
  7. In QC Rest API, when you update a test instance's status from Execution Grid, a Fast_Run_{timestamp} RUN record record is created with the same status value as that of the Test Set instance. When you update the same Test Set instance with the same Status value, the Fast_RUN record does not seem to be created. I want a run to be created against the Test Set instance, irrespective of the fact that the update has same Status value compared to the previous update. Is there a workaround for that using hp alm rest api ?

    ReplyDelete

Post a Comment