我们有一个使用惠普质量中心的项目,我们面临的一个常见问题是人们没有更新有关缺陷的评论。
所以我想我们可以提出一个小脚本或工具,可以用来定期抛出提醒并强迫用户更新评论。
我遇到了Open Test Architecture API,并且想知道我能看到的是否有任何好的Python或java示例。
由于 哈
答案 0 :(得分:13)
HP Quality Center公开了一个名为OTA的基于com的API。
此文档可从QC服务器下载 (OTA_API_Reference.chm)(奇怪的是在网上很难找到)
文档使用VBScript(官方支持的QC内部语言) 你需要在心理上翻译成Python。这通常很简单,但是 存在一些问题。
您需要在您的计算机上安装Quality Center本地代码,这是在您的Windows PC上 如果你能通过网络界面进入QC。
您还需要知道服务器的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
这不是前进的坏基础,但是我为缺陷创建了一个虚拟类并运行如下:
dfcts = [defect(b) for b in buglist]
然后我可以将工作人员代码放入缺陷类并保持整洁。 您要做的一件事是继续访问python包装器类内部的原始qc错误。
答案 1 :(得分:6)
可能查看此主题的其他人的信息。
开始这一切你需要安装pywin32,就像从这里http://sourceforge.net/projects/pywin32/files/pywin32/Build216/
一样首先,您需要导入pywin32
'''@author: www.qcintegration.com @mailto:contact@qcintegration.com'''
import pywintypes
import win32com.client as w32c
from win32com.client import gencache, DispatchWithEvents, constants
然后作为第二个操作,我在此处包含登录服务器的操作
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;
包含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;
然后连接到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;
最后如何使用示例在一个地方执行所有这些方法
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
如有任何疑问,请发送电子邮件至:contact@qcintegration.com 或直接到网络方面:http://www.qcintegration.com
答案 2 :(得分:5)
我不确定Java是否有任何好的示例,因为OTA不能直接被Java使用,它需要像JIntegra那样的Java到COM桥接。
关于Python,你可以使用Python COM api。然后任何OTA示例都可以。你有很多关于OTA的QC文档。
但我认为这里真正的问题是,你为什么要用Python或Java来做呢?为什么不使用它的工作流功能直接在QC中编写您需要的内容。这将允许您在VBScript中编写逻辑,并在用户操作的QC UI中调用它。例如,您可以绑定到缺陷/错误的Post事件,并检查是否有注释,如果没有提示用户直接发送消息。
答案 3 :(得分:2)
如果您想从Linux访问它而不运行Windows COM组件,则有REST API to HPQC(ALM11和更新版本)。
这是一个引入"要求的示例"在验证后记录(#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)
从XML解析r.text
留作练习。
答案 4 :(得分:1)
虽然您已经要求使用基于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
答案 5 :(得分:0)
您可以使用新的测试并选择允许脚本运行的类型(VPXP_API)。好的是,您已准备好在QC中拖动函数定义,而不必非常依赖doc。 我已经在Python中执行了一个实现,从QC中运行一些脚本仍然使用它的API,但是通过QC测试,这很方便直接检索结果(输出)等。通过一些shell命令,然后可以调用任何脚本服务器等...