I found a post from Anish Pillai titled “4 Different Ways to Link Function Libraries to Your QTP Scripts,” which has useful information. (See Original post here: http://www.automationrepository.com/2011/09/associate-function-library-to-qtp-script/ )
Method # 1 is the usual way to associate functions with a test; there is nothing new.
Method # 2 Using AOM (Automation Object Model)
I tried many different options, but they all seem like scripts to run a specific test from outside of QTP, and not to add a function to the current test. Here is their code in case this proves useful:
'Open QTP Set objQTP = CreateObject("QuickTest.Application") objQTP.Launch objQTP.Visible = True 'Open a test and associate a function library to the test objQTP.Open "C:\Automation\SampleTest", False, False Set objLib = objQTP.Test.Settings.Resources.Libraries 'If the library is not already associated with the test case, associate it.. If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case End
Method # 3 Using the ExecuteFile Method Has the same drawbacks that I raised in the question. It may be useful, but it is terrible for debugging in QTP 10.
Method # 4 Using the LoadFunctionLibrary method This is the most promising approach. It seems to be doing exactly what we need in order to: load the vbscript function libraries during test execution. The only catch? Only QTP 11+ seems to be . I cannot vouch for this method since I do not have QTP 11, but it looks like the perfect approach.
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs" 'Associate a single function library LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs" 'Associate more than 1 function libraries
source share