The first method: Executefile, using this function to dynamically load the external VBS, so that the test script can call the VBS file of all functions, the call statement is written below, the order cannot be reversed, otherwise it will be an error. This method is suitable for any version of QTP, but there is a drawback that code debugging can not be traced to the function of the external VBS, it is somewhat inconvenient.
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
The second method: Loadfunctionlibrary, which is the new function of QTP11, functions with Executefile, also can introduce external files, its advantage is to support code tracking debugging. Similarly, the call statement is written below, the order cannot be reversed, otherwise it will be an error.
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 the file system paths, relative paths, or quality Center paths for both Tests and Compone Nts. 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
The third method: resources, add the VBS file to QTP's resources and support code trace debugging.
File-settings-resources, click on the + number to select the file to add, click Apply, or in the left Resources sidebar, right-click "Associated Function Libraries", and then click "Associated Function Library, select the file you want to join.
Three ways to Uft scripts to call external VBS functions