使用python从质量中心读取特定的测试步骤

使用python从质量中心读取特定的测试步骤,python,python-2.7,hp-quality-center,Python,Python 2.7,Hp Quality Center,我通过OTA COM库与质量中心合作。我知道如何连接到服务器,但我对如何使用它的OTA文档感到迷茫。我需要的是创建一个函数,该函数将测试名称作为输入,并从QC返回此测试中的步骤数。 现在我在这个问题上已经走了这么远 import win32com from win32com.client import Dispatch # import codecs #to store info in additional codacs import re import json import getpass

我通过OTA COM库与质量中心合作。我知道如何连接到服务器,但我对如何使用它的OTA文档感到迷茫。我需要的是创建一个函数,该函数将测试名称作为输入,并从QC返回此测试中的步骤数。 现在我在这个问题上已经走了这么远

import win32com
from win32com.client import Dispatch
# import codecs #to store info in additional codacs
import re
import json
import getpass #for password
qcServer = "***"
qcUser = "***"
qcPassword = getpass.getpass('Password: ')
qcDomain = "***"
qcProject = "***"
td = win32com.client.Dispatch("TDApiOle80.TDConnection.1")
#Starting to connect
td.InitConnectionEx(qcServer)
td.Login(qcUser,qcPassword)
td.Connect(qcDomain, qcProject)
if td.Connected == True:
    print "Connected to " + qcProject

else:
    print "Connection failed"
#Path = "Subject\Regression\C.001_Band_tones"
mg=td.TreeManager
npath="Subject\Regression"
tsFolder = td.TestSetTreeManager.NodeByPath(npath)
print tsFolder    

td.Disconnect
td.Logout
print "Disconnected from " + qcProject

任何关于python示例或教程的帮助都将不胜感激。现在我找到了,但是没有帮助。

我找到了解决方案,如果有更好的方法,欢迎您发布

import win32com
from win32com.client import Dispatch
import getpass

def number_of_steps(name):
    qcServer = "***"
    qcUser = "***"
    qcPassword = getpass.getpass('Password: ')
    qcDomain = "***"
    qcProject = "***"
    td = win32com.client.Dispatch("TDApiOle80.TDConnection.1")

    #Starting to connect
    td.InitConnectionEx(qcServer)
    td.Login(qcUser, qcPassword)
    td.Connect(qcDomain, qcProject)
    if td.Connected is True:
        print "Connected to " + qcProject

    else:
        print "Connection failed"

    mg = td.TreeManager  # Tree manager
    folder = mg.NodeByPath("Subject\Regression")
    testList = folder.FindTests(name)  # Make a list of tests matching name (partial match is accepted)
    if testList is not None:
        if len(testList) > 1:
            print "There are multiple tests matching this name, please check input parameter\nTests matching"
            for test in testList:
                print test.name
                td.Disconnect
                td.Logout
                return False
        if len(testList) == 1:
            print "In test %s there is %d steps" % (testList[0].Name, testList[0].DesStepsNum)
    else:
        print "There are no test with this test name in Quality Center"
        td.Disconnect
        td.Logout
        return False
    td.Disconnect
    td.Logout
    print "Disconnected from " + qcProject
    return testList[0].DesStepsNum  # Return number of steps for given test

使用OTA API从质量中心获取数据通常意味着通过路径获取某些元素,创建工厂,然后使用工厂获取并搜索对象。在本例中,您需要TreeManager在测试计划中获取一个文件夹,然后需要TestFactory获取测试,最后需要DesignStepFactory获取步骤。我不是Python程序员,但我希望您能从中获得一些东西:

mg=td.TreeManager
npath="Subject\Test"
tsFolder = mg.NodeByPath(npath)
testFactory = tsFolder.TestFactory
testFilter = testFactory.Filter
testFilter["TS_NAME"] = "Some Test"
testList = testFactory.NewList(testFilter.Text)
test = testList.Item(1) # There should be only 1 item
print test.Name
stepFactory = test.DesignStepFactory
stepList = stepFactory.NewList("")
for step in stepList:
    print step.StepName

习惯QC OTA API文档需要一些时间,但我发现它非常有用。我几乎所有的知识都来自API文档中针对您的问题的示例,例如“查找唯一的测试”或“获取具有名称和路径的测试对象”。这两个示例都是测试对象的示例。即使这些示例是用VB编写的,将它们改编成Python也不是什么大事。

是的,谢谢。经过一些研究后,我最终使用了您提到的示例。我想现在我会坚持我的解决方案,因为我不需要阅读步骤,我只需要知道步骤的数量和
testList[0]。desstepsum
非常适合这个。不过,我会选择您的TSF文件夹,因为它要优雅得多。:)