Home > Okategoriserade > Importing automated test results to HP QC/ALM

Importing automated test results to HP QC/ALM

december 3rd, 2013

Background

HP QC or ALM is used by many organizations to manage quality assurance, and often the whole application life cycle. HP QuickTest Professional (which is shipped in the HP Unified Functional Testing package with HP Service Test) is integrated with QC/ALM out of the box, but other technologies like JUnit tests, Selenium tests and others often require custom solutions to integrate with QC/ALM.

HP Open Test Architecture

One solution is to use the Open Test Architecture API to interact with QC/ALM, this is a COM library provided by HP. It comes with the QC/ALM Client installation. The API provides functionality to interact with most parts of a QC/ALM project, like defects, requirements and tests. Since it is a COM library it works naturally with Visual Basic, and also with VBScript. I will be using VBScript and HP ALM in the following examples. If you are using QC some directions for the web client may not be correct, but they should be similar enough to be followed.

Prerequisites

To work with the OTA COM library from VBScript the dll-file has to be registered with Windows, this is most conveniently done by logging into QC/ALM using a browser, when logged in go to Help -> Add-ins page. Chose HP ALM Registration, read the list of requirements for the Client registration and make sure that all requirements are fulfilled. Then at the bottom of the page click Register HP ALM Client. A successful registration of the client is required to continue with the examples below..

A working knowledge of VBScript or Visual Basic is also required to follow the examples provided in this post.

TDConnection - Connecting to ALM/QC

The following code shows how to make a connection to a QC/ALM project.

Public Function ConnectToQC(ByVal server, ByVal Domain, ByVal Project)
Dim QCServer, UserName, Password, QCConnection
QCServer = server & "/qcbin"
UserName = "<qc username>"
Password = "<qc password>"

Set QCConnection = CreateObject("TDApiOle80.TDConnection")
QCConnection.InitConnectionEx QCServer
QCConnection.login UserName, Password
QCConnection.Connect Domain, Project

Set ConnectToQC = QCConnection
End Function

Dim QCConnection
Set QCConnection = ConnectToQC("http://qcservername:8080", "TEST_DOMAIN", "TEST_PROJECT")

The QC user must have the proper permissions to execute the actions in the script, just like when using the web client.

Interacting with QC/ALM objects

To create objects from the COM library, the QCConnection object created in the first code example can be used, for example to create a test instance object from a test instance in QC. The following code example is a modified example from the OTA API reference, in the reference the examples are written in Visual Basic 6.0, I have modified the following code to VBScript and changed it to comply with my requirements.

Dim TestSetFact
Dim TSTestFact
Dim theTestSet
Dim theTSTest
Dim TestSetTestsList
Dim TestSetsList
Dim tsTreeMgr
Dim tSetFolder
Dim QCConnection
Set QCConnection = ConnectToQC("http://qcserver:8080 ", "TEST_DOMAIN", "TEST_PROJECT")
Set tsTreeMgr = QCConnection.TestSetTreeManager

' Get the TDConnection.TestSetFactory.
Set TestSetFact = QCConnection.TestSetFactory
' Get the test set tree manager from the test set factory.
Set tsTreeMgr = QCConnection.TestSetTreeManager
' Get the test set folder.
Set tSetFolder = tsTreeMgr.NodeByPath("Root\Test Set Folder")
' Because we are searching for the full name,
' the list will have only one entry.
Set TestSetsList = tSetFolder.FindTestSets("Test Set 1")
Set theTestSet = TestSetsList.Item(1)
' Get the test set attributes.
Wscript.Echo "Test Set ID = " & theTestSet.ID & ", Name = " _
& theTestSet.Name & ", TestSetFolder = " & theTestSet.TestSetFolder
' Get the TSTest factory and list of TSTests.
Set TSTestFact = theTestSet.TSTestFactory
Set TestSetTestsList = TSTestFact.NewList("")

For Each theTSTest In TestSetTestsList
i = i + 1: If i > 10 Then Exit For
With theTSTest
Wscript.Echo "TSTest Name: " & .Name, "ID: " & .ID, _
"TestID: " & .testID, "Instance: " & .instance
sID = theTSTest.ID 'Save the last ID
End With
Next

This example code will create a TestSet object and a list of TSTest objects and display some of their properties.

To change a property of an object set it directly to a new value and then post it to the QC/ALM server, example:

Dim firstTestInTestList
Set firstTestInTestList = TestSetTestsList.Item(2)
firstTestInTestList.Status = "Failed"
firstTestInTestList.Post

Closing the connection

The last step of the script should be to clean up the connection.

QCConnection.Disconnect
QCConnection.Logout
QCConnection.ReleaseConnection

Conclusion

Working with the OTA API is pretty straight forward and can have very useful real life applications. If an applications quality assurance is tracked using QC/ALM then integration between test automation and QC/ALM is, in my opinion, necessary to facilitate a smooth work flow.

For further reading on the subject see the OTA API reference, the reference is available from the QC/ALM web client.

Frank Lindholm Okategoriserade

  1. No comments yet.
  1. No trackbacks yet.
Security Code: