Tuesday, June 8, 2010

Running QTP tests using Python

Running QTP tests using Python

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

-------------------------------
  • import win32com, win32com.client
  • qtp = win32com.client.Dispatch("QuickTest.Application")
  • # starts up QTP
  • qtp.Launch()
  • # make the QTP window visible
  • qtp.Visible = True
  • # Open a test, replace the path
  • qtp.Open("C:\Tests\test1")
  • # to open a QTP test in Quality Center
  • # qtp.Open(r"[QualityCenter] Subject\FolderName\QTPScript")
  • # create a RunResultsOptions object
  • qtResultsOpt = win32com.client.Dispatch("QuickTest.RunResultsOptions")
  • # set the location to where the results will be save
  • qtResultsOpt.ResultsLocation = "C:\Test\test1\res"
  • qtp.Test.Run(qtResultsOpt)
  • print "Test has %s" %qtp.Test.LastRunResults.Status
  • # close the Test
  • qtp.Test.Close()
  • # quit QTP
  • qtp.Quit()
---------------------------

Thanks to :
http://bulkan-evcimen.com/running_qtp_test_using_python/

No comments:

Post a Comment