Navigate back to the homepage

Running QTP tests using Python

Bulkan Evcimen
September 18th, 2009 · 1 min read

Photo by Bruce Tang on Unsplash

QTP provides an interface called the automation object model. This model is essentially a COM interface providing a bunch of objects that can be used to automate QTP. The full object list is available in the QuickTest Professional Automation documentation.

Running QTP tests from the command line is useful for doing scheduled automatic testing. If you use a continuous integration system to do automatic builds of your software, you can run your QTP tests on the latest build.

The following is a Python script that is able to run a test and print out Passed or Failed. It is a direct port of example code in the documentation written in VBScript

1import win32com, win32com.client
2
3qtp = win32com.client.Dispatch("QuickTest.Application")
4
5# starts up QTP
6qtp.Launch()
7
8# make the QTP window visible
9qtp.Visible = True
10
11# Open a test, replace the path
12qtp.Open("C:\Tests\test1")
13
14# to open a QTP test in Quality Center
15# qtp.Open(r"[QualityCenter] Subject\FolderName\QTPScript")
16
17# create a RunResultsOptions object
18qtResultsOpt = win32com.client.Dispatch("QuickTest.RunResultsOptions")
19
20# set the location to where the results will be save
21qtResultsOpt.ResultsLocation = "C:\Test\test1\res"
22
23qtp.Test.Run(qtResultsOpt)
24
25print "Test has %s" %qtp.Test.LastRunResults.Status
26
27# close the Test
28qtp.Test.Close()
29
30# quit QTP
31qtp.Quit()

More articles from Bulkan

Using Vuejs with Parcel and p5.js

Photo created by grid-art.bulkan.dev This is part two of a two part series. In part one I showed you how you can setup a project using…

August 23rd, 2020 · 1 min read

Using Parcel, TypeScript with p5.js

Photo created by grid-art.bulkan.dev This is part one of a two part series and you can read Part two . p5.js is already great at being…

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