Sunday, January 26, 2014

Library Files

Inorder to modularize the script, library Files are added to the QTP Script. It contains variable declaration, Functions, Classes etc. They enable reusability that can be shared across test scripts. They are saved with an extenstion .vbs or .qfl
A New Library File can be Created by Navigating to "File" >> "Function Library"

Associating Function Libraries

1 : By using "File" > "Settings" > Resources > Associate Function Library option. Click on "+" Button to Add Function Library File and add it using actual path or relative path.
2 : Using ExecuteFile method.
  'Syntax : ExecuteFile(Filepath)
  ExecuteFile "C:\lib1.vbs" 
  ExecuteFile "C:\lib2.vbs" 
3 : Using LoadFunctionLibrary Method.
  'Syntax : LoadFunctionLibrary(Filepath)
  LoadFunctionLibrary "C:\lib1.vbs" 
  LoadFunctionLibrary "C:\lib2.vbs" 
4 : Automation Object Model(AOM) - It is a mechanism using which we can control various QTP operations outside QTP. Using AOM, we can launch QTP, Open the Test, Associate Function Libraries etc. The Following Vbscript should be saved with Extension .vbs and upon executing the same, QTP will be launched and test would start executing. AOM will be discussed in detail in the later chapters.
 'Launch QTP
 Set objQTP = CreateObject("QuickTest.Application")
 objQTP.Launch
 objQTP.Visible = True
  
 'Open the test
 objQTP.Open "D:\GUITest2", False, False
 Set objLib = objQTP.Test.Settings.Resources.Libraries
  
 'Associate Function Library if NOT associated already.
 If objLib.Find("C:\lib1.vbs") = -1 Then 
   objLib.Add "C:\lib1.vbs", 1 
 End