Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to associate Function Libraries to test in QTP/UFT??

When you are creating QTP/UFT scripts or designing any Framework, you will need to associate Function Libraries to them. This can be done Manually or even through scripting.

Here I would like to show you both the ways of Associating a Function Library. The Association can be made in 4 ways.
  1. Using File-> Settings
  2. Using AOM
  3. Using ExecuteFile method
  4. Using LoadFunctionLibrary method

1. Using File->Settings

This is the common and manual method of associating the Function Library. Find below the step by step procedure of doing it

  1. After opening the Test, click on File menu
  2. Click on Settings under file menu. You can see a Window open with name Test Settings
  3. Here, click on the Resources on the left tab. You will see a new Frame in right showing Resources and a empty box below
  4. Here we can click on the plus (+) button and browse and select the function library we need to associate.
  5. After adding the libraries, click on Apply and OK.

2. Using AOM

AOM means Automation Object Model. This is a mechanism using which one can control various operations from outside the QTP. Using AOM, we can even write a code to open QTP test and associate Library Function.

    AOM to open QTP test
        'Open QTP
     Set objQTP = CreateObject("QuickTest.Application")
     objQTP.Visible = True
     'Open a test and associate a function library to the test
     objQTP.Open "C:AutomationSampleTest", False, False     

    AOM to associate a library

        Set objLib = objQTP.Test.Settings.Resources.Libraries
    'If the library is not already associated with the test case, associate it..
    'If library is not already added
    If objLib.Find("C:SampleFunctionLibrary.vbs") = -1 Then 
        'Associate library to test case
        objLib.Add "C:SampleFunctionLibrary.vbs", 1 

3. Using ExecuteFile method

ExecuteFile statement executes all the VBScript statements present in the specified file, thus making all the functions, sub-routines and other elements available to the action as globally. This is how to use the ExecutionFile method:

'Action begins
     ExecuteFile "C:YourFunctionLibrary.vbs" 

4. Using LoadFunctionLibrary

LoadFunctionLibrary is a new method which was introduced in QTP 11, which would allow us to load a function library when the step runs. We can load multiple function libraries in a single line using a comma delimeter. This is how to use the LoadFunctionLibrary method:

     'Associate a single function library
    LoadFunctionLibrary "C:YourFunctionLibrary_1.vbs" 
    'Associate more than 1 function libraries
    LoadFunctionLibrary "C:FuncLib_1.vbs", "C:FuncLib_2.vbs" 

This post first appeared on Quick Test Professional (QTP) & Test Automation Gu, please read the originial post: here

Share the post

How to associate Function Libraries to test in QTP/UFT??


Subscribe to Quick Test Professional (qtp) & Test Automation Gu

Get updates delivered right to your inbox!

Thank you for your subscription