Tuesday, March 2, 2010

QTP - Add library files using AOM script

QTP - Add library files using AOM script

If you have more than 10 library files, it is very difficult to add these files manually from the Test settings and also there is possibility of missing few files.

You can run the following script, so that system will perform your work automatically.

Note: Change folder path and number of library folders(my script use two folders) as per your design.
'QTP Test Path
sQTPpath = "C:\Automation FrameWork\Frame_Work GeP"

'Test Core library
sCoreLib = "C:\Automation FrameWork\Library\CoreLibraries\"

'Test Main library
sGeneralLib = "C:\Automation FrameWork\Library\"


' Don't update any of the below items ******************************************

Set App = CreateObject("QuickTest.Application")
If App.Launched Then ' If QuickTest is  open
        App.Quit 
End If
App.Launch
App.Visible = True
App.WindowState = "Maximized"
App.Open sQTPpath

'Set the Libraries collection object
Set qtLibraries = App.Test.Settings.Resources.Libraries

qtLibraries.RemoveAll

Set fso = CreateObject("Scripting.FileSystemObject")


If sCoreLib = null Then
    Wscript.Echo "No Folder parameter was passed"
    Wscript.Quit
End If

Set folder = fso.GetFolder(sCoreLib)
Set files = folder.Files

For each folderIdx In files
    iLen = Len(folderIdx.Name)
    If Ucase(mid(folderIdx.Name,iLen-3,4)) = ".VBS" Then
            qtLibraries.Add sCoreLib & folderIdx.Name, qtLibraries.Count+1
    End If
Next

If sGeneralLib = null Then
    Wscript.Echo "No Folder parameter was passed"
    Wscript.Quit
End If

Set folder = fso.GetFolder(sGeneralLib)
Set files = folder.Files

For each folderIdx In files
    iLen = Len(folderIdx.Name)
    If Ucase(mid(folderIdx.Name,iLen-3,4)) = ".VBS" Then
            qtLibraries.Add sGeneralLib & folderIdx.Name, qtLibraries.Count+1
    End If
Next



App.Test.Save
Wscript.Echo "Script successfully added " & qtLibraries.Count & " Libraries"

Set app = Nothing
Set qtlibraries = Nothing
Set fso = Nothing
Set folder = Nothing
Set files = Nothing

---

No comments:

Post a Comment