Thursday, October 8, 2009

ExecuteGlobal

ExecuteGlobal

1.
Firstly we have an add.vbs file saved as C:\add.vbs.



2.
Write the below function in a notepad and Save it as a .vbs file. I saved it as c:\include_file.vbs.



Above we are passing the path of a text file to include_file function and creating a file system object, opening a text file (ReadAll() method reads the entire contents of a text file and returns it as a string), then there is an ExecuteGlobal statement with the contents of the file as its argument.

ExecuteGlobal executes a string of VBScript code in a script's global namespace, which means that the executed code will be accessible anywhere in the script. Functions, sub-routines and variables can be included in the executed string, and their particular declarations will be available any time you need them all through the rest of your code.

3.
Open a new test in QTP and go to File->Settings->Resources and include that file in "Associated function libraries".



4.
And write the below 3 lines in QTP test.



5.
Now run the test. It will show 5 in message box, the value which is returned by addFunction. This is just another way of including any file (add.vbs in our case) in a QTP test via some function (include_file.vbs in our case) using ExecuteGlobal.

Also See:

ExecuteFile
QTP Function Library
QTP Function Library - Example 1
QTP Function Library - Example 2
QTP Function Library - Example 3
QTP Function Library - Example 4