Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to load and Associate Function libraries in QTP Test at runtime

Below are the various ways by which we can add/associate libraries with QTP tests so that functions in the libraries can be used within test.

ExecuteFile Statement 

      Executes the VBScript statements in the specified file. Functions, subroutines defined in the file are available from the global scope of the action's script.We cannot debug functions or statement contained in the file.

ExecuteFile "C:\BusinessLib.vbs”

Through QTP Interface 

      A library can be associated with a test so that the functions and subroutines, classes defined in the function library can be used .This can be achieved as follows:
      Navigate to File > Settings > Resources > Associate Function Library’ option in QTP. Add the required Libraries to the resources by clicking on + icon.

      Once function library is associated with the test.We can debug function in the function libraries and view function definition of the functions from the scripts.We can also define the priority of function library using up and down icon.

     
Associating Libraries with QTP tests

     

Using Load Function Library method

In  QTP 11, and onwards, We can dynamically load function library with the test using load function library. Libraries are released from test once completed. We can debug into function on calling library using LoadFunctionLibrary. The scope of the library is local to the action in which it is called.

Syntax: LoadFunctionLibrary “D:\TestLib.vbs”


We can add multiple files seperated by


Using Automation Object Model 

We can associate multiple libraries to QTP test using the below code. Also all the tests actions can use the functions from associated libraries.

strFilesNameCommaSeperated = "d:\test1.vbs,d:\test.vbs"
strTestName ="D:\Sample\Test1"
Call LoadLibrariesThroughAOM(strFilesNameCommaSeperated,strTestName)
Public Function LoadLibrariesThroughAOM(strFilesNameCommaSeperated,strTestName)
Set oqtapp = CreateObject("QuickTest.Application")
oqtapp.Launch
oqtapp.Visible = True
 strLibName = split(strFilesNameCommaSeperated,",")
'Open a test and associate a function library to the test
oqtapp.Open strTestName, False, False
Set oLib = oqtapp.Test.Settings.Resources.Libraries
 For i = 0 to ubound(strLibName)
                 LibName = strLibName(i)
                 ' If library is not already added, add the required library.
 
                If oLib.Find(LibName) = -1 Then
                         oLib.Add LibName, 1
                End If
 Next
oqtapp.Test.Save
                End Function


No comments:

Post a Comment