Monday 27 February 2012

4 Different Ways to Associate Function Libraries to your QTP Scripts


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.
Associate function Library to QTP
Associate function Library to QTP

7 comments:

  1. Have you ever considered about including
    a little bit more than just your articles? I mean, what you say
    is important and all. However just imagine if you added some great pictures or video clips to give your
    posts more, "pop"! Your content is excellent but with pics and clips, this blog could undeniably be one of the greatest in its niche.
    Superb blog!

    Here is my web site minecraft net

    ReplyDelete
  2. Nice blog here! Also your site loads up fast! What web host are you using?
    Can I get your affiliate link to your host? I wish my
    site loaded up as fast as yours lol

    Also visit my web blog :: quest protein bars free sample

    ReplyDelete
  3. Wonderful beat ! I wish to apprentice while you amend
    your web site, how could i subscribe for a blog web site?
    The account helped me a appropriate deal. I had been tiny bit acquainted of this your broadcast offered
    shiny clear idea

    my web blog ... Quest Bars

    ReplyDelete
  4. I blog often and I seriously thank you for your content.
    This article has really peaked my interest. I'm going to bookmark your blog and
    keep checking for new details about once per week.
    I subscribed to your RSS feed too.

    my page ... Quest bar

    ReplyDelete
  5. Yes! Finally someone writes about discount code. Quest Bars blogesaurus

    Visit my weblog :: Quest bars Lawsuit

    ReplyDelete
  6. I was curious if you ever considered changing the page layout
    of your site? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content
    so people could connect with it better. Youve got an awful lot of text
    for only having 1 or 2 pictures. Maybe you could space it out
    better?

    my homepage; Where Can You Find Quest Bars

    ReplyDelete
  7. I have to thank you for the efforts you've put in writing this blog.
    I'm hoping to check out the same high-grade blog posts from
    you later on as well. In fact, your creative writing
    abilities has encouraged me to get my own site now ;)

    My webpage :: Lose Weight for Women

    ReplyDelete