2014-03-24 44 views
0

我正在通过OTA COM库与Quality Center合作。我想出了如何连接到服务器,但是我在OTA文档中丢失了关于如何使用它的信息。我需要的是创建一个函数,它将测试名称作为输入并返回来自QC的此测试中的步骤数。 现在我在这个问题上这么远。使用python阅读Quality Center的特定测试步骤

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示例或教程的任何帮助将不胜感激。现在我发现了thisthis,但他们没有帮助。

回答

0

我想出了解决方案,如果有更好的方法来做到这一点,欢迎您发布。

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 
1

使用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文档中的示例 - 对于您的问题,有一些示例,如“查找独特测试”或“使用名称和路径获取测试对象”。这两个示例都是Test对象的示例。即使这些例子是在VB中,将它们适配到Python应该不是什么大事。

+0

是的,谢谢。经过一番调查后,我最终会处理你提到的例子。我认为现在我会坚持我的解决方案,因为我不需要阅读步骤,我只需要知道步骤的数量和'testList [0] .DesStepsNum'适合这一点很好。不过,我会让你的tsFolder定义它更优雅。 :) – arbulgazar

相关问题