4 Different Ways to Associate Function Libraries to your QTP Scripts

From: http://www.automationrepository.com/2011/09/associate-function-library-to-qtp-script/

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.



Let’s 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.

Associate function Library to QTP

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.

'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

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.

'Action begins
ExecuteFile "C:\YourFunctionLibrary.vbs"
 
'Other logic for your action would come here
'.....

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.

'Some code from the action
'.....
 
LoadFunctionLibrary "C:\YourFunctionLibrary_1.vbs" 'Associate a single function library
LoadFunctionLibrary "C:\FuncLib_1.vbs", "C:\FuncLib_2.vbs" 'Associate more than 1 function libraries
 
'Other logic for your action would come here
'.....

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.. :–)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 该资源内项目源码是个人的课程设计,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用! ## 项目备注 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值