QTP脚本调用外部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”,选择要加入的文件即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值