Function Definition Generator is a utility available in UFT enabling you to define the definitions of function as well as subroutines with other options. It is a very useful utility for users who are new to visual basic programming and UFT.
In this article, I will discuss the following
Create a new Function and Subroutine
The Function Definition Generator utility inserts the function definition either in the function library or in the current Action of the Test depending on whichever is the active document. So it’s up to your choice in which you want to add the function definition to be added.
Go to Design > Function Definition Generator and enter the function name in the Name field.
To define a function you just have to write the function name in the Name field. The preview of the function definition would be displayed in the “Preview” section as shown below.
Insert Function to Script
Click on the “OK” button. The function definition would be added in the active document( function library or current action) with an empty body. You can add your code to the body of the function.
Public Function MyTestFunction
' TODO: add function body here
In the same way, you can define the definition for a subroutine by selecting Type as Subroutine.
Add Function Arguments
You can also add arguments/parameters of a function or a subroutine. In the Arguments section click on the + icon add to provide the name of the argument. It could be anything. By default, the pass mode is By reference, you can change it to By value if required and click on the “OK” button. The function definition as showing up in the preview will be inserted in the active document.
Add Documentation Details
You can also write a description of the function in the description field. The documentation field is also a free text field you can describe the parameter details here. For example, if you want to pass the date as in the input parameter, you can describe the format of the date either is dd/mm/yyyy or mm/dd/yyyy. It also shows function parameters in the form of a list item if you click on the arrow right arrow icon to get the parameter added in the documentation field. Both description and Documentation are options and free text. Whatever you write there it gets added in the function library or action in the form of a comment.
Register a User-Defined Function
If you are planning to register a user-defined function and forgot the syntax, this utility is worth utilizing. Enter the function name and select the class of the Test Object. Also, select which method of the class you want to override. I will be discussing more how to register a user-defined function in my next post. The syntax of registering the function would be generated automatically.
Add Function Body
Once you have inserted the function definition in your action or function library and write the body of the script by replacing the TODO comment. The function would become ready to be used.
- The Ultimate Cheat Sheet on Step Generator in UFT
- All You Need to Know about Checkpoints In UFT
- Action Input And Output Parameters In UFT
- Settings.WebPackage Replaytype in UFT
- How To Use Dictionary Object in UFT With Examples
- Find a Matching Pattern in String Using Regular Expression in UFT
- Descriptive Programming in UFT with Examples