Skip to content

Instantly share code, notes, and snippets.

@bulkan
Created May 9, 2011 23:46
Show Gist options
  • Save bulkan/963655 to your computer and use it in GitHub Desktop.
Save bulkan/963655 to your computer and use it in GitHub Desktop.
Export test cases in QC using Python
import win32com, win32com.client
import HTMLParser
class MLStripper(HTMLParser.HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def get_fed_data(self):
return ''.join(self.fed)
def sanitize(data):
s = MLStripper()
s.feed(data)
return s.get_fed_data()
def recursiveExport(f, qc, node):
if not node:
return
f.write('%s, %s\n' %(node.Name,sanitize(node.Description)))
print node.Name
if node.Count <= 0:
# Node has only test cases
tests = node.FindTests('')
if not tests:
# FindTests returns None if there are no test cases
tests = []
for test in tests:
designStepFactory = test.DesignStepFactory
f.write(',%s,%s\n' %(test.ID, test.Name))
print test.ID, test.Name
# print out the "Design Step" for each test case
for ds in designStepFactory.NewList(''):
StepDescription = sanitize(ds.StepDescription)
StepName = sanitize(ds.StepName)
StepExpectedResult = sanitize(ds.StepExpectedResult)
f.write(',,,,%s,%s,%s\n' %(StepName, StepDescription, StepExpectedResult))
f.flush()
# current node has more children
elif node.Count > 0:
for child in node.NewList():
if child:
recursiveExport(f, qc, child)
f.write('\n')
def exportTests(qc, nodePath):
f = open(r'export.csv','w')
f.write(',ID, TEST NAME, ,,Step, Description, Expected Result\n')
mg = qc.TreeManager
node = mg.NodeByPath(nodePath)
recursiveExport(f, qc, node)
f.close()
if __name__ == "__main__":
print 'Logging in...'
qc = win32com.client.Dispatch("TDApiOle80.TDConnection")
qc.InitConnection("http://qc:8080/qcbin")
qc.Login("<username>", "<password>")
qc.Connect("<domain>", "<project?")
"""
Change nodePath to another "folder" in the Test Plan section of QC and run script
"""
exportTests(qc, nodePath='Subject\\Some Folder')
@rushabh12
Copy link

qc = win32com.client.Dispatch("TDApiOle80.TDConnecton")

File "C:\Python27\lib\site-packages\win32com\client_init_.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment