您的位置:首页 > 编程语言 > Python开发

Python 实现QC Test Plan 数据遍历

2014-01-02 00:00 411 查看
摘要: 由于之前需要检查每天QC中的case执行情况,而QC的登录已经查询是在是太麻烦了,而且很慢。我自己就想用python写个脚本直接出报告。由于python基础不是很好,于是就开始查阅各种资料,但是关于python的的QC操作实在是太少了。后来在一个国外的大牛那里看到了关于QC 的介绍,QC原来还有一个OTA API接口来用在2次开发。于是就开始了挖掘如何使用这个接口了。最后在google大叔和度娘的帮助下,东拼西凑。实现了 Test Plan中报告的抓取。

Python 代码如下:
#coding=utf-8
'''**************************Parameter************************************************'''
# 这里的参数根据自己想要的路径和Test Set设置,INSTANCE_INFO开关是指遍历TEST SET中最后一次的执行结果,RUN_INFO是指每一条instance的执行记录
TEST_SET_PATH = r"Root\Test Sets\ReleaseQ1304\FB1311\New Feature"
TEST_SET_NAME = r"RP000539_6b_1"
INSTANCE_INFO=True
RUN_INFO=True

'''**********************************START********************************************'''
from win32com.client import Dispatch
qcServer = "https://10.135.55.13/qcbin"
qcUser = "xianjche"
qcPassword = "#EDCvfr4"
qcDomain = "MBB_BTS"
qcProject = "RP_BTS_IV"

def get_QCConnection(qcServer,qcUser,qcPassword,qcDomain,qcProject):
'''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")
QCConnection.InitConnectionEx(qcServer)
QCConnection.Login(str(qcUser), str(qcPassword))
QCConnection.Connect(qcDomain, qcProject)
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()
qcConn = get_QCConnection(qcServer,qcUser,qcPassword,qcDomain,qcProject)
#-----------------------------截至这里,创建了一个QC的链接对象
def getInstance(qcConn,test_folder,test_set):
'''
This funtion is to get the test set objects and return the instances 
3ff8
;in the set as
a list object.
'''
TestSetTreeManager = qcConn.TestSetTreeManager
TSetFolder = TestSetTreeManager.NodeByPath(test_folder)
TestSetList = TSetFolder.FindTestSets(test_set)
return TestSetList

def printCaseInfo(name,object,data_name):
print name + ": ",object.Field(data_name)

def RunInfoOfCase(tsInstanceobject):
#     print the detail of every instance run results like this:
#     RN_STATUS:  Failed
#     RN_EXECUTION_DATE:  11/11/13 00:00:00
#     SW build:  RP10970
#     RN_USER_59:  [Pre-check:RP000539_1a]BM don't update  top master statuses/activity in IM object RP Rel3
#     *******
RunFactory = tsInstanceobject.RunFactory
obj_theRun = RunFactory.NewList("")

for result in obj_theRun:
#printCaseInfo("Case Name",result,"TS_NAME")
printCaseInfo("RN_STATUS",result,"RN_STATUS")
printCaseInfo("RN_EXECUTION_DATE",result,"RN_EXECUTION_DATE")
printCaseInfo("SW build",result,"RN_USER_01")
#RN_USER_01,这里是QC管理员定义好的数据库字段,当时我是一个一个是出来的这个字段是对应的测试包的信息
printCaseInfo("Comments",result,"RN_USER_59")
print "*******"

def lastInfoOfCase(TestSetList,InstanceIfo=True,runInfo=False):
for tsItem in TestSetList:
tsTestList = tsItem.TSTestFactory.NewList("")
print tsTestList.count
# loop through all test cases in this list
for tsTestCase in tsTestList:
#         print "Case Name: ",tsTestCase.Field("TS_NAME")
#         print "TC_STATUS: ",tsTestCase.Field("TC_STATUS")
#         print "Comments: ",tsTestCase.Field("TC_USER_01")
#         print "Release: ",tsTestCase.Field("TC_USER_02")
#         print "SW Build: ",tsTestCase.Field("TC_USER_03")
if InstanceIfo == True:
print "-------------------------------------------------------------------------"
printCaseInfo("Case Name",tsTestCase,"TS_NAME")
printCaseInfo("TC_STATUS",tsTestCase,"TC_STATUS")
printCaseInfo("Release",tsTestCase,"TC_USER_02")
printCaseInfo("SW Build",tsTestCase,"TC_USER_03")
printCaseInfo("Priority",tsTestCase,"TC_USER_12")
#         printCaseInfo("Platform",tsTestCase,"TC_USER_01")
#         printCaseInfo("Location",tsTestCase,"TC_USER_01")
#         printCaseInfo("Organization",tsTestCase,"TC_USER_01")
#         printCaseInfo("Feature",tsTestCase,"TC_USER_01")
#         printCaseInfo("ExecDate",tsTestCase,"TC_EXEC_DATE")
printCaseInfo("ExecDate",tsTestCase,"TC_VTS")
#         printCaseInfo("Detailed Automation Level",tsTestCase,"TC_USER_01")
#         printCaseInfo("Instance Description",tsTestCase,"TC_USER_01")
printCaseInfo("Responsible Tester",tsTestCase,"TC_TESTER_NAME")
printCaseInfo("Comments",tsTestCase,"TC_USER_01")
#                 print "-------------------------------------------------------------------------"
if runInfo == True:
RunInfoOfCase(tsTestCase)
if __name__ == "__main__":
TestSetList = getInstance(qcConn,TEST_SET_PATH,TEST_SET_NAME)
lastInfoOfCase(TestSetList,InstanceIfo=INSTANCE_INFO,runInfo=RUN_INFO)
#--+==========================================================================
put_QCConnection(qcConn)
print raw_input("the end!!!!!!!!!!!!!")

这里还只是一个登录到查询测试结果的一个大概的框架,有很多地方可以完善,比如:
可以从新定义TEST_SET_PATH,TEST_SET_NAME为一个字典或者列表,这样就可以每次导出多个Test SET的报告。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python QC test set