UFT脚本调用外部VBS函数的三种方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UFT脚本调用外部VBS函数的三种方法相关的知识,希望对你有一定的参考价值。

第一种方法:ExecuteFile,利用该函数将外部vbs动态地加载进来,使测试脚本可以调用vbs文件的所有函数,调用语句写在下方,顺序不能颠倒,否则会报错。这个方法适用于QTP任何版本,但有个缺点,代码调试时不能跟踪到外部vbs的函数中,多少有些不便。

 

 

ExecuteFile File

 

File  String  The absolute or relative path of the file to execute.

 

Example:

ExecuteFile "c:\out.vbs"

OutputMsg

 

-----------out.vbs-----------

Sub OutputMsg    msgbox "Hello world!" End Sub

 

 

第二种方法:LoadFunctionLibrary,这是QTP11新增的函数,功能同ExecuteFile,也能够引入外部文件,它的好处是支持代码跟踪调试。同样,调用语句写在下方,顺序不能颠倒,否则会报错。

 

LoadFunctionLibrary(Path)

 

File  String  The absolute or relative path of the file to execute.

Path  String  The path (or paths) of the function library to load. You can specify one or more absolute file system paths, relative paths, or Quality Center paths for both tests and components. If you specify multiple paths, separate them using a comma delimiter.

 

Example:

LoadFunctionLibrary "c:\out.vbs"

OutputMsg

 

-----------out.vbs-----------

Sub OutputMsg    msgbox "Hello world!" End Sub

 

 

第三种方法:Resources,将VBS文件加入QTP的Resources中,支持代码跟踪调试。

File-Settings-Resources,点击+号选择要加入的文件,点击Apply;或者在左侧Resources边栏,右键点“Associated Function Libraries”,再点“Associated Function Library”,选择要加入的文件即可。

以上是关于UFT脚本调用外部VBS函数的三种方法的主要内容,如果未能解决你的问题,请参考以下文章

UFT demo程序

vb.net2005中如何调用外部vbs文件

QTP调用外部函数

Springboot中调用外部接口的三种方式

JSJavaScript 脚本的三种使用形式:行内脚本内部脚本外部脚本

shell调用另一个脚本的三种方式fork/exec/source