Monday, February 9, 2009

QTP Scripts 27 - How to add any path in the Search List '(Tools -> Options -> Folders tab) through a script.

'How to add any path in the Search List '(Tools -> Options -> Folders tab) through a script.

'We are opening a test called "call twra" and adding a path C:\Program Files\Mercury Interactive\QuickTest Professional\Tests in the Search List '(Tools -> Options -> Folders tab)

Dim qtp_app
Dim str_path

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

qtp_app.Open "C:\Program Files\Mercury Interactive\QuickTest Professional\Tests\call twra", True, False

'If the folder C:\Program Files\Mercury Interactive\QuickTest Professional\Tests is not there just add it.
str_path = qtp_app.Folders.Locate ("C:\Program Files\Mercury Interactive\QuickTest Professional\Tests")

‘If the folder is not found in the collection, add it

If qtp_app.Folders.Find (str_path) = -1 Then
qtp_app.Folders.Add str_path, 1 'Add the folder to the collection
End If

'If you have moved "<current test>" downwards in the list, bring it back to first position.

If qtp_app.Folders.Item (2) = "<current test>" Then
qtp_app.Folders.MoveToPos 1, 2
End If