How can I import a function into my QTP test during its launch?

I have built many functions for QTP 10 tests, and many of these functions depend on other related functions. I would like my functions to import any other functions that they need. Currently, I have to perform each of my functions and manually bind each of my dependencies.

Although I know that ExecuteFile "C:\Functions\SampleFunction.vbs" will work, the disadvantage is that QTP cannot display any code that it just imported. This means that debugging the code is a nightmare, since QTP will show this yellow debugging pointer on lines that do not correspond to the actual code being executed. In short, this approach is a mess.

Is there any other command that will import other .vbs files into QTP at runtime, so I can get the functions to import other functions that they need?

+2
source share
1 answer

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 
+2
source

Source: https://habr.com/ru/post/945578/


All Articles