Saturday, January 3, 2009

QTP Script 26 - How to run all tests in a specific folder in QuickTest professional (QTP)?

'For this script I created three tests tr1, tr2 and tr3. In the Expert View of tr1 I wrote just one line - msgbox ("Test 1"), in the Expert View of tr2 - msgbox ("Test 2") and in the Expert View of tr3 - msgbox ("Test 3"). I went to C:\Program Files\HP\QuickTest Professional and created a folder named "tests1". I then moved folders tr1, tr2 and tr3 which belong to tests I created from C:\Program Files\HP\QuickTest Professional\Tests to tests1 folder (C:\Program Files\HP\QuickTest Professional\tests1) which I created above and gave the same path in the script. Now this code will run all the tests (3 in our case) in that folder.

Dim qtp_app
Dim file_sys
Dim Dir
Dim test_collection

Set qtp_app = CreateObject("QuickTest.Application")
qtp_app.Launch
qtp_app.Visible = True

' The file_systemObject object is used to access the file system on the server. This object can manipulate files, folders, and directory paths.
Set file_sys = CreateObject("Scripting.filesystemObject")

'GetFolder: Returns a Folder object for a specified path
Set Dir = file_sys.GetFolder( "C:\Program Files\HP\QuickTest Professional\tests1" )

Set test_collection = Dir.SubFolders

'RunResultsOptions:A collection of properties that indicate preferences for the run results.
Set qtResultsObj = CreateObject("QuickTest.RunResultsOptions")

For each t_folder in test_collection
qtp_app. Open t_folder.Path, True, False
'Setting the location for the run results
qtResultsObj.ResultsLocation = t_folder.Path & "\Res1" ' Set the results location
' Execute the test. Instruct QuickTest Professional to wait for the test to finish executing.
qtp_app.Test.Run qtResultsObj, True
qtp_app.Test.Close
Next

qtp_app.Quit

Set test_collection = Nothing
Set Dir = Nothing
Set file_sys = Nothing
Set qtp_app = Nothing