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

2024-10-08 18:28:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我通过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示例或教程的帮助都将不胜感激。现在我找到了this和{a2},但它们没有帮助。在


Tags: tofromimportclientwin32comtddispatchprint
2条回答

使用otaapi从质量中心获取数据通常意味着通过路径获取一些元素,创建一个工厂,然后使用工厂来搜索对象。在您的例子中,您需要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

它需要一些时间来适应qcotapi文档,但我发现它非常有用。我几乎所有的知识都来自API文档中针对您的问题的示例,例如“查找唯一测试”或“获取具有名称和路径的测试对象”。这两个示例都是测试对象的示例。即使这些例子是用VB编写的,让它们适应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

相关问题 更多 >

    热门问题