Anda di halaman 1dari 6

4 Different Ways to Associate Function Libraries to your QTP Scripts -... http://www.automationrepository.com/2011/09/associate-function-librar...

Subscribe to get new articles directly in your mailbox

Home
About
All Articles
Download
QTP Tutorials
Contact Me
QTP Websites

169

By Anish Pillai Anish Pillai Posted under QTP Basic Stuff

4 Different Ways to Associate Function Libraries to your QTP Scripts

3
FLARES

Most of the times, when you are creating test scripts or are designing a new QTP Framework, you would be trying to
come up with reusable functions which you would have to store in the function library. Now, in order to use this function
library with multiple test cases, you need to associate this function library with your scripts. This article explains the
4 methods that will help you in associating the function libraries in QTP Test Cases.

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.
2) By using Automation Object Model (AOM).
3) By using ExecuteFile method.
4) using LoadFunctionLibrary method.

Lets see in detail how each of these methods can be used to map function libraries to your test scripts.

1. Using File > Settings > Resources > Associate Function Library option from the Menu
bar

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.

1 of 6 1/29/2016 8:16 AM
4 Different Ways to Associate Function Libraries to your QTP Scripts -... http://www.automationrepository.com/2011/09/associate-function-librar...

Subscribe to get new articles directly in your mailbox

Associate function Library to QTP

2. Using AOM (Automation Object Model)

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 'Open QTP
2 Set objQTP = CreateObject("QuickTest.Application")
3 objQTP.Launch
4 objQTP.Visible = True
5
6 'Open a test and associate a function library to the test
7 objQTP.Open "C:\Automation\SampleTest", False, False
8 Set objLib = objQTP.Test.Settings.Resources.Libraries
9
10 'If the library is not already associated with the test case, associate it..
11 If objLib.Find("C:\SampleFunctionLibrary.vbs") = -1 Then ' If library is not already added
12 objLib.Add "C:\SampleFunctionLibrary.vbs", 1 ' Associate the library to the test case
13 End

3. 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 'Action begins
2 ExecuteFile "C:\YourFunctionLibrary.vbs"
3
4 'Other logic for your action would come here
5 '.....

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 'Some code from the action


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

2 of 6 1/29/2016 8:16 AM
4 Different Ways to Associate Function Libraries to your QTP Scripts -... http://www.automationrepository.com/2011/09/associate-function-librar...

Subscribe to get new articles directly in your mailbox


8 '.....

This was all about the different ways using which you can associate function libraries to QTP Scripts. What are your
views on this article? Can you think of any other points which I have missed and can be added here? Please let us know
your views using the comments section. Happy Reading.. :)

If you enjoyed this article, you can join our blog to get free email updates directly in your inbox.

To check out more tutorials, visit our QTP Tutorials page. You can also check the Archives page to view the list of all our articles.

3
FLARES

No related posts.

AOM, Associate Function Library, ExecuteFile, Function Library, LoadFunctionLibrary, QTP 11

3 of 6 1/29/2016 8:16 AM
4 Different Ways to Associate Function Libraries to your QTP Scripts -... http://www.automationrepository.com/2011/09/associate-function-librar...

Subscribe to get new articles directly in your mailbox


26 Comments
1

Meera

What is the difference between Executefile and Loadfunctionlibrary statements?


Amith CJ

Four primary differences:

1. If you have a user defined class in your library file, you need to use ExecuteFile.
QTP will not load them if you use LoadFunctionLibrary.

2. ExecuteFile can load one library file per statement while you can load many library
files in a single LoadFunctionLibrary statement (you need to separate library file paths
using a comma).

3. ExecuteFile is a VB thing is around good old days. LoadFunctionLibrary is a


relatively newer one in QTP (not sure when it was added).

4. Using ExecuteFile will not allow to go into the function in debug mode using F11
while LoadFunctionLibrary allows you to do that.

So which one do I use?

LoadFunctionLibrary because of point #4 above. I occasionally use ExecuteFile if I


have a class defined (see point #1).

Sidhant Raj

thanks a lot...it helped me immediately


Ashok Kakade

Hi All

Can we Load only one function from Function Library which have multilple functions ?

Sumit Kumar Verma

what is the script in QTP to run both (flight 3a & 4a) flight reservation app?

Stephan Coetzee

Hi,

Thank you for the informative article.

I do however have one question: What is the best way to update the function library if I were
to update object names in the OR (Object Repository)? According to me the function library is

4 of 6 1/29/2016 8:16 AM
4 Different Ways to Associate Function Libraries to your QTP Scripts -... http://www.automationrepository.com/2011/09/associate-function-librar...

Subscribe to get new articles directly in your mailbox

Don't miss any new articles!! Enter your email id to get


updates in your inbox.

**** Your Opinion Matters ****

QTP Expertise
What's your expertise level in QTP?
Just Started

Beginner Level

Intermediate Level

Expert Level

Other (please specify)

View Results

Total Answers 1725


Total Votes 1725

5 of 6 1/29/2016 8:16 AM
4 Different Ways to Associate Function Libraries to your QTP Scripts -... http://www.automationrepository.com/2011/09/associate-function-librar...

Subscribe to get new articles directly in your mailbox

2011-2013. Automation Repository. By Anish Pillai [Google+].


The content on this blog is copyrighted and may not be reproduced on other websites. Privacy Policy

6 of 6 1/29/2016 8:16 AM

Anda mungkin juga menyukai