Qtp 简明教程

QTP - Library Files

为了将脚本模块化,已将库文件添加到 QTP 脚本中。它包括变量声明、函数、类等。它们实现了可重用,可在测试脚本之间共享。它们通过扩展名 .vbs 或 .qfl 保存。

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 −

qtp library 1

@{}− 使用 ExecuteFile 方法。

Method 2 − Using ExecuteFile method.

'Syntax : ExecuteFile(Filepath)
ExecuteFile "C:\lib1.vbs"
ExecuteFile "C:\lib2.vbs"

@{}− 使用 LoadFunctionLibrary 方法。

Method 3 − Using LoadFunctionLibrary Method.

'Syntax : LoadFunctionLibrary(Filepath)
LoadFunctionLibrary "C:\lib1.vbs"
LoadFunctionLibrary "C:\lib2.vbs"

Method 4 − 自动化对象模型(AOM) - 这是一个用于控制 QTP 外部各种 QTP 操作的机制。通过 AOM,我们可以启动 QTP,打开测试,关联函数库等。应使用扩展名 .vbs 保存以下 VbScript,并在执行它时,QTP 将启动并开始执行测试。将在后一章节详细讨论 AOM。

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