使用 Python 或 Java 自动化 HP Quality Center
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2627419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automating HP Quality Center with Python or Java
提问by Hari
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.
我们有一个使用 HP Quality Center 的项目,我们面临的常见问题之一是人们不更新对缺陷的评论。
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.
我遇到了开放测试架构 API,想知道是否有任何我能看到的好的 Python 或 java 示例。
Thanks Hari
谢谢哈里
采纳答案by Alex Shnayder
I'm not sure there are any good samples for Java, because OTA can't be consumed by Java directly, it needs a Java to COM bridnge like JIntegra.
我不确定 Java 有什么好的示例,因为 OTA 不能直接被 Java 使用,它需要像JIntegra这样的 Java 到 COM 桥接器。
About Python, well you can use PythonCOM api's. And then any OTA example will do. You got plenty in QC documentation of OTA.
关于 Python,你可以使用PythonCOM api。然后任何 OTA 示例都可以。您在 OTA 的 QC 文档中有很多。
But I think the real question here is, why would you want to do it in Python or Java. Why not write what you need directly in QC using it's Workflow feature. Which will allow you to write your logic in VBScript, and have it invoked inside QC UI on user actions. For instance you can bind to the Post event of a Defect / Bug and check if there is a comment and if there is not prompt the user directly with a message.
但我认为这里真正的问题是,你为什么要用 Python 或 Java 来做这件事。为什么不使用它的工作流功能直接在 QC 中编写您需要的内容。这将允许您在 VBScript 中编写逻辑,并在用户操作的 QC UI 中调用它。例如,您可以绑定到缺陷/错误的 Post 事件并检查是否有评论以及是否没有直接用消息提示用户。
回答by Fabrice MARIANADIN
You can use a new Test and select type (VPXP_API) which allow script to run. The good thing there is that you'd have the function definition ready to be dragged from within QC instead of having to heavily rely on doc. I've done an implementation in Python running some script from within QC still using its API but via a QC test which is handy to retrieve directly the result (Output) etc.. going through some shell command which can then call any script on any server etc...
您可以使用新的测试并选择允许脚本运行的类型 (VPXP_API)。好消息是,您可以将函数定义从 QC 中拖出,而不必严重依赖 doc。我已经在 Python 中完成了一个实现,从 QC 中运行一些脚本仍然使用它的 API,但是通过一个 QC 测试,它可以方便地直接检索结果(输出)等。通过一些 shell 命令,然后可以调用任何脚本服务器等...
回答by you cad sir - take that
Example of using Python (win32com) to connect to HP Quality Center via OTA
使用 Python (win32com) 通过 OTA 连接到 HP Quality Center 的示例
HP Quality Center exposes a com based API called OTA.
HP Quality Center 公开了一个基于 com 的 API,称为 OTA。
Documentation on this is downloadable from an QC server (OTA_API_Reference.chm) (Weirdly it is very hard to find online)
这方面的文档可从 QC 服务器 (OTA_API_Reference.chm) 下载(奇怪的是,很难在网上找到)
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.
该文档使用 VBScript(官方支持的 QC 内部语言),您需要在心理上转换为 Python。这通常非常简单,但存在一些问题。
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.
您需要在您的机器上安装 Quality Center 本地代码,如果您能够通过 Web 界面访问 QC,则该代码安装在您的 Windows PC 上。
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.
您还需要知道服务器的 URL、您的用户名和密码以及您正在处理的 QC 项目的域。
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.
然后我可以将工人代码放入缺陷类并保持整洁。您想要做的一件事是保持对 python 包装类内部的原始 qc 错误的访问。
回答by user2277544
Information for others who may view this thread.
可能查看此线程的其他人的信息。
To start all this You will need install pywin32, like from here http://sourceforge.net/projects/pywin32/files/pywin32/Build216/
要开始这一切,您需要安装 pywin32,就像从这里http://sourceforge.net/projects/pywin32/files/pywin32/Build216/
First of all You will need to import pywin32
首先你需要导入pywin32
'''@author: www.qcintegration.com @mailto:[email protected]'''
import pywintypes
import win32com.client as w32c
from win32com.client import gencache, DispatchWithEvents, constants
Then as second operation I include here action on login to 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;
Second of all method which will include OTAapi dll file
第二种方法将包含 OTAapi dll 文件
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 main method to connect to QCserver
然后连接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 at the end how to execute all of those methods in one place with 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 more question mailto: [email protected] or directly to web side: http://www.qcintegration.com
如有任何问题,请发送邮件至:[email protected] 或直接发送至网页:http://www.qcintegration.com
回答by Mark Lakata
There is a REST API to HPQC(ALM11 and newer) if you want to access it from Linux without running a Windows COM component.
如果您想在不运行 Windows COM 组件的情况下从 Linux 访问HPQC(ALM11 和更新版本),则有一个REST API。
Here is an example that pulls in a "requirement" record (# 1202) after authenticating.
这是一个在验证后拉入“要求”记录(#1202)的示例。
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)
The parsing of r.text
from XML is left as an exercise.
解析r.text
from XML留作练习。
回答by Sohel
Though you have asked for a Python or Java based solution, sharing the following VBA code that you can use insde HPQC/ALM's script editor (Defects module script) to accomplish the goal.
尽管您已要求基于 Python 或 Java 的解决方案,但共享以下 VBA 代码,您可以使用内置 HPQC/ALM 的脚本编辑器(缺陷模块脚本)来实现目标。
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