HP Quality Center Automation with Python or Java

We have a project that uses the HP Quality Center, and one of the common problems we face is people who do not update comments on the defect.

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

I came across the Open Test Architecture API and wondered if there are any good Python or java examples for what I could see.

Thanks Hari

+7
java python hp-quality-center
source share
6 answers

I’m not sure that there are good samples for Java, because OTA cannot be consumed directly by Java, for this you need Java for COM-bridnge, for example JIntegra .

About Python, you can use the Python COM api. And then any OTA example will do. You have a lot in the QC OTA documentation.

But I think that the real question arises here: why do you need to do this in Python or Java. Why not write what you need right in QC using the Workflow function. This will allow you to write your logic in VBScript and invoke it in the QC user interface in user actions. For example, you can bind to a Post event from Defect / Bug and check if there is a comment, and if there is no direct user request with a message.

+5
source share

Python example (win32com) for connecting to HP Quality Center through OTA

The HP Quality Center provides a COM-based API called OTA.

The documentation on this can be downloaded from the QC server (OTA_API_Reference.chm) (oddly very hard to find on the Internet)

The documentation uses VBScript (an officially supported internal language for quality control) and you will need to mentally translate it into Python. This is usually very simple, but there are a couple of fixes.

You will need to install a local quality center code on your computer, this is on your Windows PC if you have access to QC through the web interface.

You also need to know the server URL, as well as the username and password, as well as 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 moving forward, however, I create a dummy class for defects and run something like:

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

Then I can put the working code in the defect class and keep things neat. One thing you want to do is keep access to the raw qc error inside the python shell class.

+13
source share

Information for others who can view this topic.

To start all this, you will need to install pywin32, for example from here http://sourceforge.net/projects/pywin32/files/pywin32/Build216/

First of all you will need to import pywin32

 '''@author: www.qcintegration.com @mailto:contact@qcintegration.com''' import pywintypes import win32com.client as w32c from win32com.client import gencache, DispatchWithEvents, constants 

Then, as a second operation, I include here the action on entering the server

 def connect_server(qc, server): '''Connect to QC server input = str(http adress) output = bool(connected) TRUE/FALSE ''' try: qc.InitConnectionEx(server); except: text = "Unable connect to Quality Center database: '%s'"%(server); return qc.Connected; def connect_login(qc, username, password): '''Login to QC server input = str(UserName), str(Password) output = bool(Logged) TRUE/FALSE ''' try: qc.Login(username, password); except pywintypes.com_error, err: text = unicode(err[2][2]); return qc.LoggedIn; def connect_project(qc, domainname, projectname): '''Connect to Project in QC server input = str(DomainName), str(ProjectName) output = bool(ProjectConnected) TRUE/FALSE ''' try: qc.Connect(domainname, projectname) except pywintypes.com_error, err: text = "Repository of project '%s' in domain '%s' doesn't exist or is not accessible. Please contact your Site Administrator"%(projectname, domainname); return qc.ProjectConnected; 

The second way that will include the OTAapi dll file

 def qc_instance(): '''Create QualityServer instance under variable qc input = None output = bool(True/False)''' qc= None; try: qc = w32c.Dispatch("TDApiole80.TDConnection"); text = "DLL QualityCenter file correctly Dispatched" return True, qc; except: return False, qc; 

Then the main method of connecting to QCserver

 def qcConnect(server, username, password, domainname, projectname): print("Getting QC running files"); status, qc = qc_instance(); if status: print("Connecting to QC server"); if connect_server(qc, server): ##connected to server print("Checking username and password"); if connect_login(qc, username, password): print("Connecting to QC domain and project"); if connect_project(qc, domainname, projectname): text = "Connected" connected = True; return connected, text; else: text = "Not connected to Project in QC server.\nPlease, correct DomainName and/or ProjectName"; connected = False; return connected, text; else: text = "Not logged to QC server.\nPlease, correct UserName and/or Password"; connected = False; return connected, text; else: text = "Not connected to QC server.\nPlease, correct server http address"; connected = False; return connected, text; else: connected = False; text = "Unable to find QualityCenter installation files.\nPlease connect first to QualityCenter by web page to install needed files" return connected, text; 

And in the end, how to execute all these methods in one place with an example of use

 if __name__ == "__main__": server= r"http://qualitycenterServer:8080/qcbin" username= "alex_qc" password= "" domainname= "DEFAULT" projectname= "QualityCenter_Demo" connection_status, text = qcConnect(server, username, password, domainname, projectname); print "connection_status:", connection_status 

In case of any questions mailto: contact@qcintegration.com or directly to the web page: http://www.qcintegration.com

+6
source share

REST API for HPQC (ALM11 and newer) if you want to access it from Linux without using the Windows COM component.

Here is an example that drags out a claim record (# 1202) after authentication.

 import requests session = requests.session() user='hpqc' password='xxxxx' r = session.get("http://hpqc-server:8080/qcbin/authentication-point/authenticate",auth=(user,password)) r = session.get("http://hpqc-server:8080/qcbin/rest/domains/Foo/projects/Bar/requirements/1202") print(r.text) 

Parsing r.text from XML remains as an exercise.

+1
source share

Although you asked for a Python or Java-based solution using the following VBA code, you can use the HPQC / ALM script insde editor (script defect module) to achieve the goal.

 Function Bug_FieldCanChange(FieldName, NewValue) On Error Resume Next if not changed then strCommentBeforeUpdate = Bug_Fields("BG_DEV_COMMENTS").Value end if If FieldName = "BG_DEV_COMMENTS" and blnAddCommentClicked = False Then Msgbox "Cannot update the comments." & Chr(13)& "Changes made will not be saved."&Chr(13)& "Please use 'Add comment' button to insert new comment." &Chr(13)& " Or click Cancel without saving." blnUpdateCommentError = true blnAddCommentClicked = False changed = true End If Bug_FieldCanChange = DefaultRes End Function 
+1
source share

You can use the new Test and select type (VPXP_API), which let you run the script. It’s good that you have a function definition ready to be dragged from QC, rather than relying heavily on the document. I have implemented a Python implementation that runs some script from QC, still using its own API, but through a QC test, which is convenient for directly receiving the result (Output), etc., Passing through some shell command, which can then call any script on any server, etc.

0
source share

All Articles