Using a function library
QuickTest Professional does not support declaring functions in one Action and using them in another Action.
If you include your functions in a loaded library written in VBScript, you may call those functions from any location in the test. This is particularly useful when you want to reuse code that performs certain steps.
You call a function procedure using the function name, followed by the argument list. If your function returns a value, the argument list should appear within parentheses.
QuickTest Professional 6.0 or higher
1. Create the function library file.
2. Associate the function library with the test script. For information on associating a function library, refer to Document ID 46019 – How to associate a function library with a test.
3. Call the function in the script, as needed.
‘ Function library is loaded in File -> Settings -> Resources tab.
‘ Call the MakeReverseUpper function.
RevName = MakeReverseUpper ("Homer")
To enter a function call using the Keyword View, use the Step Generator. If you have registered the function to a QuickTest Professional Test Object (using RegisterUserFunc), you will call the function as you would a built in QuickTest Professional test method.
QuickTest Professional 5.6 or below
1. Create a FileSystemObject.
2. Open the library file.
3. Read the file in to a variable.
4. Execute the library code (within the variable).
The following example illustrates the use of a function that converts a string to uppercase and reverses the order of the letters.
‘ Test script:
Dim fso, f, libcode, RevName
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("C:\Libcode.txt", 1)
libcode = f.ReadAll
RevName = MakeReverseUpper ("Homer") ‘ Function returns "REMOH"
‘ Function Library (Filename: C:\Libcode.txt)
Function MakeReverseUpper (s)
rev = StrReverse (s)
MakeReverseUpper = UCase (rev)