Create and register a user-defined function using the Function Definition Generator

Relevant for: GUI tests and components

This topic describes how to create and register a user-defined function using the Function Definition Generator.

Open the function library/test and the Function Definition Generator

  1. Make sure that the function library or action in which you want to insert the function definition is the active document. This is because the Function Definition Generator inserts the function in the currently active document after you finish defining it.

  2. Select Design > Function Definition Generator.

Back to top

Specify the details

  1. In the Function definition section, give the function a unique name.

  2. Select the type for the function: Function or sub (subroutine).

  3. Specify the type for the function:

    • Public: The function can be called by any test or component (via the application area) associated with the function library

    • Private: The function can be called only from this function library.

    Note: If you are overriding an existing test object class method, select the Public option.

Back to top

Register the function to a test object class - optional

  1. Below the function name, select the Register to a test object check box.

  2. Select the test object from the list of available objects.

  3. Enter the name of a new operation that you want to add to the test object class, or select an existing operation to specify the operation that you want to override its standard functionality. The name of the method cannot contain spaces.

  4. If necessary, specify that this operation is the default operation for test objects of this type.

    Tip: If you choose not to register your function at this time, you can manually register it later by adding a RegisterUserFunc statement. You can also add additional RegisterUserFunc statements, to register the function to additional test object classes.

Back to top

Add argument

  1. In the Arguments box, click the Add button to add the necessary arguments for the function.

  2. For each argument, in the Pass mode cell, specify how the value is passed to the function:

    • By value: A value entered into the function

    • By reference: The function references the value.

Back to top

Add documentation details

In the Additional information box, enter the details of the function:

  • Description: The description of the function displayed as a tooltip when you hover over the function name.

  • Documentation: The description of the function displayed in the Documentation column of the Keyword View after you enter the necessary arguments.

Back to top

Insert the function

Click OK or Insert. UFT One inserts the generated VBScript code in the active document.

Back to top

Add the content (code)

To finalize the function, add content to the function code, as required, replacing the TODO comment.

The function is now available to your tests, components, or function libraries (depending on where the function was generated and the context in which you are working). If you registered the function to a test object, this function is displayed in the list of available functions for the test object (in the Keyword View and Editor).

Back to top