How to associate function library at runtime in UFT- Complete code

The function library is the backbone of any test automation framework. You can associate function library at runtime using AOM. It is designed to handle all the inputs, outputs, exceptions, and whatnot. 

In UFT, there are mainly two types of function libraries supported. 

  • In-built function library in UFT- This is written with the extension .qfl file
  • VBScript function library- This is written with extension .vbs

Unlike object repository, both of these library types can be added as an external dependency file into UFT.

This can be achieved either through the settings window of UFT by providing the location of the file or at runtime through code.

In order to associate function library at runtime, first you need to create an object of Settings like below.

Set qtLibraries = qtApp.Test.Settings.Resources.Libraries

Now you can add a function library to this object by using add method of this object like below:

qtLibraries.Add "D:\libraary.vbs", 1 

Once this statement is executed, the function library is loaded into the scope of execution. This can be used to associate both types of function libraries i.e. .qfl and .vbs.

Please find below the complete example code snippet on how to add a function library at runtime in UFT.

How to associate function library at runtime in UFT- Code Snippet
Dim qtApp
Dim qtTest
Dim qtLibraries
'Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
'If QTP is notopen then open it
If  qtApp.launched <> True then
qtApp.Launch
End If
'Make the QuickTest application visible
qtApp.Visible = True
qtApp.Open "C:\Program Files\HP\QuickTest Professional\Tests\trial", False
'Get the libraries collection object
Set qtLibraries = qtApp.Test.Settings.Resources.Libraries
'If the library file "libraary.vbs" is not assiciates with the Test then associate it
If qtLibraries.Find("D:\libraary.vbs") = -1 Then
    qtLibraries.Add "D:\libraary.vbs", 1 
End If
'Save the test
qtApp.Test.Save
'Close QTP
qtApp.quit
'Release Object
Set qtLibraries = Nothing
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object

You may also read

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.