Question

I am working with Quality Center via OTA COM library. I figured out how to connect to server, but I am lost in OTA documentation on how to work with it. What I need is to create a function which takes a test name as an input and returns number of steps in this test from QC. For now I am this far in this question.

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

Any help on descent python examples or tutorials will be highly appreciated. For now I found this and this, but they doesn't help.

Was it helpful?

Solution 2

I figured out the solution, if there is a better way to do this you are welcome to post it.

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

OTHER TIPS

Using the OTA API to get data from Quality Center normally means to get some element by path, create a factory and then use the factory to get search the object. In your case you need the TreeManager to get a folder in the Test Plan, then you need a TestFactory to get the test and finally you need the DesignStepFactory to get the steps. I'm no Python programmer but I hope you can get something out of this:

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

It takes some time to get used to the QC OTA API documentation but I find it very helpful. Nearly all of my knowledge comes from the examples in the API documentation—for your problem there are examples like "Finding a unique test" or "Get a test object with name and path". Both examples are examples to the Test object. Even if the examples are in VB it should be no big thing to adapt them to Python.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top