`
kiki1120
  • 浏览: 307314 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

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

    博客分类:
  • QTP
 
阅读更多

第一种方法: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”,选择要加入的文件即可。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics