Function
Library – Part 1
What are Function Libraries?
Apart from UFT test objects, methods
and in-built functions we can add user defined functions containing
VBScript code for each business functions, sub-routines, statements
or scripts which needs to be incorporated in multiple actions or
codes.
A function library is a separate
VBScript code file which can be saved as a text file and associated
with UFT tests.
We cannot use a function library with
a test without associating the function library with the test.
How does UFT work with Function
Libraries?
- Create a function library using VBScript and save it as a .qfl or .vbs or text file.
- Associate the required function libraries with the Test.
- Only after associating function libraries to the tests we can call the functions, sub-routines by the required actions.
- During run time UFT loads all the function libraries, it is associated with, to access the functions.
- UFT searches the function from the Associated Function Library list and if there are functions with the same name the first function is selected.
- The priority of function libraries are as per the list in the solution explorer.
Using a function library
dynamically or without associating
We can do that by using the statement
LoadFunctionLibrary statement.
If there is a conflict in the names of
a dynamically loaded function library and associated function
library then dynamically loaded function library is given priority.
Registering a function as an
operation to a test object class
We can register a function as an
operation to a test object class using RegisterUserFunc.
By using the keyword RegisterUserFunc
in an action or function library to register a function to a test
object class. We can use this as a defined operation for that class
of object.
Eg -: RegisterUserFunc "WebEdit",
"MySet", "MySetFunc", True
WebEdit is the class to which the
"MySet"(cannot contain spaces) named operation is getting
added with the help of the "MySetFunc" user-defined
function.
The True argument at the end of the
statement makes the operation its default operation.
Using UnregisterUserFunc
By using UnregisterUserFunc we can
unregister a user-defined function that has already been registered
with the register function.
Unregistering user-defined methods are
important to avoid errors in the normal functioning of built-in UFT
methods or test failures.
LoadFunctionLibrary and ExecuteFile
statements
For a TEST - In
LoadFunctionLibrary the code in the function library is
available for the complete run session for the complete test.
For a COMPONENT – The
LoadFunctionLibrary the code in the function library is
available within the scope of the calling component.
In the case of ExecuteFile
statement the code of the file is available only within the calling
action or component.
LoadFunctionLibrary enables
debugging of code in the function library during run time.
ExecuteFile statement does not
allow debugging of code and also while using this statement
and debugging a test or component, the
execution marker may not be correctly displayed.
This comment has been removed by the author.
ReplyDelete