Navigate back to the homepage

Export Test Cases From Quality Center Using Python

Bulkan Evcimen
May 10th, 2011 · 1 min read

Photo by Dieter de Vroomen on Unsplash

Here is a Python script that will export out test cases in a folder from Quality Center into a CSV file.

The following script will not handle Attachments. Will work on that later when I have time.

1import win32com, win32com.client
2
3import HTMLParser
4class MLStripper(HTMLParser.HTMLParser):
5 def __init__(self):
6 self.reset()
7 self.fed = []
8
9
10 def handle_data(self, d):
11 self.fed.append(d)
12
13
14 def get_fed_data(self):
15 return ''.join(self.fed)
16
17
18def sanitize(data):
19 s = MLStripper()
20 s.feed(data)
21 return s.get_fed_data()
22
23
24def recursiveExport(f, qc, node):
25 if not node:
26 return
27 f.write('%s, %s\n' %(node.Name,sanitize(node.Description)))
28 print node.Name
29
30 if node.Count <= 0:
31 # Node has only test cases
32 tests = node.FindTests('')
33 if not tests:
34 # FindTests returns None if there are no test cases
35 tests = []
36
37 for test in tests:
38 designStepFactory = test.DesignStepFactory
39 f.write(',%s,%s\n' %(test.ID, test.Name))
40 print test.ID, test.Name
41
42 # print out the "Design Step" for each test case
43 for ds in designStepFactory.NewList(''):
44 StepDescription = sanitize(ds.StepDescription)
45 StepName = sanitize(ds.StepName)
46 StepExpectedResult = sanitize(ds.StepExpectedResult)
47 f.write(',,,,%s,%s,%s\n' %(StepName, StepDescription, StepExpectedResult))
48 f.flush()
49
50 # current node has more children
51 elif node.Count > 0:
52 for child in node.NewList():
53
54 if child:
55 recursiveExport(f, qc, child)
56 f.write('\n')
57
58
59def exportTests(qc, nodePath):
60 f = open(r'export.csv','w')
61 f.write(',ID, TEST NAME, ,,Step, Description, Expected Result\n')
62
63 mg = qc.TreeManager
64 node = mg.NodeByPath(nodePath)
65 recursiveExport(f, qc, node)
66 f.close()
67
68
69if __name__ == "__main__":
70 print 'Logging in...'
71 qc = win32com.client.Dispatch("TDApiOle80.TDConnection")
72 qc.InitConnection("http://qc:8080/qcbin")
73 qc.Login("<username>", "<password>")
74 qc.Connect("<domain>", "<project?")
75
76 """
77 Change nodePath to another "folder" in the Test Plan section of QC and run script
78 """
79 exportTests(qc, nodePath='Subject\\Some Folder')

More articles from Bulkan

Exporting a csv file with web.py

Photo by Mika Baumeister on Unsplash This is how you export a csv file and get the browser to recognize that its a csv file and popups the…

November 25th, 2007 · 1 min read

embryo.py and py2app awesomeness

Photo by Bulkan Evcimen on Unsplash At work i created this script that changes permissions on our application BizarShop so that it works…

November 5th, 2007 · 2 min read
© 2007–2020 Bulkan
Link to $https://twitter.com/bulkanevcimenLink to $https://github.com/bulkanLink to $https://instagram.com/bulkan.evcimen