Tuesday, June 2, 2009

Associating a library file to test at RunTime manually in QTP?

If we associate a library file(classes,functions and procedures) at Run time then scope of the variables or objects of that library file will not be available to all the actions except to the only action where execute file statement is executed..

If we want the scope to be across all the actions then we have two ways of doing it:

1.attach that library file manually from File->Settings -> Resources.
2.use the below code which you need to run before qtp tool is open
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Launch QuickTest
qtApp.Visible = True ' Set QuickTest to be visible
' Open a test and get its libraries collection
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries ' Get the libraries collection object
' Add Utilities.vbs if it's not in the collection
If qtLibraries.Find("C:\lib1.vbs") = -1 Then ' If the library cannot be found in the collection
msgbox "not assosiated"
qtLibraries.Add "C:\lib1.vbs", 1 ' Add the library to the collection
End If
Set qtLibraries = Nothing ' Release the test's libraries collection
Set qtApp = Nothing ' Release the Application object
RunAction "Action2", oneIteration

No comments:

Post a Comment