Wednesday, 10 June 2015

QTP - 24 - Associating library to QTP :

Based on the type of framework you are using, you can use any of the following methods to associate function libraries to your QTP Script -

1) By using ‘File > Settings > Resources > Associate Function Library’ option in QTP.
This is the most common method 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.

2) By using Automation Object Model (AOM).

QTP AOM is a mechanism using which you can control various QTP operations from outside QTP. Using QTP Automation Object Model, you can write a code which would open a QTP test and associate a function library to that test.

Example: Using the below code, you can open QTP, then open any test case and associate a required function library to that test case. To do so, copy paste the below code in a notepad and save it with a .vbs extension.
1
2
3
4
5
6
7
8
9
10
11
12
13
'Open QTP
Set objQTP = CreateObject("QuickTest.Application")
objQTP.Launch
objQTP.Visible = True
'Open a test and ass
objQTP.Open "C:\Automation\SampleTest", False, False
Set objLib = objQTP.Test.Settings.Resources.Libraries
'If the library is


















If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then '
  objLib.Add "C:\SampleFunctionLibrary.vbs", 1 '
3) By 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 (function library) 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.

1
2
3
4
5

ExecuteFile "C:\YourFunctionLibrary.vbs"





4) 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.

1
2
3
4
5
6
7
8
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs"
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs"

No comments:

Post a Comment