I found a post by Anish Pillai called "4 Different Ways to Associate Function Libraries to your QTP Scripts", that has some useful info. (See the 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; nothing new there.
Method #2 Using AOM (Automation Object Model)
I've tried many different variations, but all of them seem to be scripts for launching a specific test from outside of QTP, not for adding a function to a running test.
Here's their code in case it 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 ExecuteFile Method
Has the same downfalls that I brought up in the question. Could be useful, but it's horrible for debugging within QTP 10.
Method #4 Using LoadFunctionLibrary Method
This is the most promising approach. It appears to do exactly what we need it to: load vbscript function libraries while the test is running. The only catch? It appears to be QTP 11+ only. I can't vouch for this method since I don't 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
LoadFunctionLibrary
and reloading the same library multiple times (like you would do with@import
orusing
in other libraries)? QTP10 user here, but just curious because... you know, I just want to know. – Darladarlan