The different methods using which you can associate function libraries to your QTP Script are – usingAOM, using ExecuteFile method, using LoadFunctionLibrary method and by using ‘File > Settings > Resources > Associate Function Library’ option in QTP. Let’s see how each of these methods can be used to map function libraries to your test scripts.
1. Using AOM (Automation Object Model)
QTP AOM is a mechanism using which you can control various QTP operations using another application. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test. Refer the below code to see how it can be done.
'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
2. Using ExecuteFile Method
ExecuteFile statement executes all the VBScript statements in a specified file. After the file has been executed, all the functions, subroutines and other elements from the file are available to the action as global entities. Simply put, once the file is executed, its functions can be used by the action. You can use the below mentioned logic to use ExecuteFile method to associate function libraries to your script.
'Action begins
ExecuteFile "C:\YourFunctionLibrary.vbs"
'Other logic for your action would come here
'.....
3. Using LoadFunctionLibrary Method
LoadFunctionLibrary, a new method introduced in QTP 11 allows you to load a function library when a step runs. You can load multiple function libraries from a single line by using a comma delimiter.
'Some code from the action
'.....
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs", "C:\YourFunctionLibrary_2.vbs"
'Other logic for your action would come here
'.....
4. Using ‘File > Settings > Resources > Associate Function Library’ option from the Menu bar
This is one of the most common methods used to associate a function library to a test case. To use this method, select File > Settings option from the Menu bar. This will display the ‘Test Settings’ window. Click on Resources from the left hand side pane. From the right hand side pane, click on the ‘+’ button and select the function library that needs to be associated with the test case.
0 comments:
Post a Comment