Automating HP Quality Center with Python or Java

Hari picture Hari · Apr 13, 2010 · Viewed 32.1k times · Source

We have a project that uses HP Quality Center and one of the regular issues we face is people not updating comments on the defect.

So I was thinkingif we could come up with a small script or tool that could be used to periodically throw up a reminder and force the user to update the comments.

I came across the Open Test Architecture API and was wondering if there are any good Python or java examples for the same that I could see.

Thanks Hari

Answer

you cad sir - take that picture you cad sir - take that · May 23, 2011

Example of using Python (win32com) to connect to HP Quality Center via OTA

HP Quality Center exposes a com based API called OTA.

Documentation on this is downloadable from an QC server (OTA_API_Reference.chm) (Weirdly it is very hard to find online)

The documentation uses VBScript (The officially supported internal language for QC) and you will need to mentally translate to Python. THis is usually very simple, but a couple of gotchas exist.

You will need to install on your machine the Quality Center local code, this is on your windows PC if you have been able to get to QC through the web interface.

You will also need to know the URL of the server and you username and password and the domain of the QC project you are working on.

from win32com.client import Dispatch

conn = get_QCConnection()

for bug in get_bugs(qcConn):
    print bug.Title

put_QCConnection(conn)

#below code needs to be in seperate module or at least above the fold but here 
# for clarity

def get_QCConnection():
    '''Get the hardcoded connection to the server and domain.
    Can be made a "real" engine if you try hard.
    Use makepy utility to determine if the version number has changed (TDApiOle80)
    but this works to current version'''

    QCConnection = Dispatch("TDApiOle80.TDConnection")
    url = "http://qc.example.com/qcbin"
    QCConnection.InitConnectionEx(url)
    QCConnection.login("USER", "PASS")
    QCConnection.Connect("google_projects", "Google_Chrome")    
    return QCConnection

def put_QCConnection(qcConn):
    #If one person logged in to QC changes *anything* on a bug,
    # they hold a global lock on writing to that bug till 
    # thier session times out, so really really remember to logout
    # its painful to wait for your own session to time out

    qcConn.Logout()

def get_bugs(qcConn):
    '''just following boiler plate from vbscript
    PS the SetFilter is not in QTA API, it uses Filter.  
    But due to the workarounds in 
    the very brilliant pythoncom code it supplies a virtual wrapper class
    called SetFilter - this is one of those gotchas '''

    BugFactory = qcConn.BugFactory
    BugFilter = BugFactory.Filter

    BugFilter.SetFilter(u"Status", "New") 
    #NB - a lot of fields in QC are malleable - and vary from site to site. 
    #COntact your admins for a real list of fields you can adjust
    buglist = BugFilter.NewList()
    return buglist       

This is not a bad basis for going forward, however I create a dummy class for defects and run something like:

dfcts = [defect(b) for b in buglist]

Then I can put worker code into defect class and keep things neater. One thing you want to do is keep access to the raw qc bug internal to the python wrapper class.