QTP - Library Files
In order 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
Method 1 − By using "File" > "Settings" > Resources > Associate Function Library option. Click the "+" button to add Function Library file and add it using the actual path or relative path as shown below −
Method 2 − Using ExecuteFile method.
'Syntax : ExecuteFile(Filepath) ExecuteFile "C:\lib1.vbs" ExecuteFile "C:\lib2.vbs"
Method 3 − Using LoadFunctionLibrary Method.
'Syntax : LoadFunctionLibrary(Filepath) LoadFunctionLibrary "C:\lib1.vbs" LoadFunctionLibrary "C:\lib2.vbs"
Method 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