Adding a Function to the Function Generator - WinRunner

When you add a function to the Function Generator, you specify the following:

  • how the user supplies values for the arguments in the function
  • the function description that appears in the Function Generator

Note that after you add a function to the Function Generator, you should associate the function with a category. See “Associating a Function with a Category”

You use the generator_add_function TSL function to add a user-defined function to the Function Generator.

To add a function to the Function Generator:

  1. Open the Function Generator. (Choose Insert > Function > From Function Generator, click the Insert Function from Function Generator button on the User toolbar, or press the INSERT FUNCTION FROM FUNCTION GENERATOR softkey.)
  2. In the Category box, click function table.
  3. In the Function Name box, click generator_add_function.
  4. Click Args. The Function Generator expands.
  5. In the Function Generator, define the function_name, description, and arg_number arguments:
    • In the function_name box, type the name of the new function between the quotes. Note that you can include spaces and upper-case letters in the function name.
    • In the description box, enter the description of the function between the quotes. Note that it does not have to be a valid string expression and it must not exceed 180 characters.
    • In the arg_number box, you must choose 1. To define additional arguments (up to eight arguments for each new function), you must manually modify the generated generator_add_function statement once it is added to your test script.
  6. For the function’s first argument, define the following arguments: arg_name, arg_type, and default_value (if relevant):
    • In the arg_name box, type the name of the argument within the quotation marks. Note that you can include spaces and upper-case letters in the argument name.
    • In the arg_type box, select “browse()”, “point_object”,point_window”, “select_list (01)”, or “type_edit”, to choose how the user will fill in the argument’s value in the Function Generator, as described in “Defining Function Arguments”
    • In the default_value box, if relevant, choose the default value for the argument.
    • Note that any additional arguments for the new function cannot be added from the Function Generator: The arg_name, arg_type, and default_value arguments must be added manually to thegenerator_add_function statement in your test script.
  7. Click Paste to paste the TSL statement into your test script.
  8. Click Close to close the Function Generator.

Note: You must run the test script in order to insert a new function into the Function Generator.

Defining Function Arguments

The generator_add_function function has the following syntax:

  • function_name is the name of the function you are adding.
  • description is a brief explanation of the function. The description appears in the Description box of the Function Generator when the function is selected. It does not have to be a valid string expression and must not exceed 180 characters.
  • arg_number is the number of arguments in the function. This can be any number from zero to eight.

For each argument in the function you define, you supply the name of the argument, how it is filled in, and its default value (where possible). When you define a new function, you repeat the following parameters for each argument in the function: arg_name, arg_type, and default_value.

  • arg_name defines the name of the argument that appears in the Function Generator.
  • arg_type defines how the user fills in the argument’s value in the Function Generator. There are five types of arguments. , , , , or “

“browse()” The value of the argument is evaluated by pointing to a file in a browse file dialog box. Use browse when the argument is a file. To select a file with specific file extensions only, specify a list of default extension(s). Items in the list should be separated by a space or tab. Once a new function is defined, the browse argument is defined in the Function Generator by using a Browse button.

“point_object”:The value of the argument is evaluated by pointing to a GUI object (other than a window). Use point_object when the argument is the logical name of an object. Once a new function is defined, the point_object argument is defined in the Function Generator by using a pointing hand.

“point_window”:The value of the argument is evaluated by pointing to a window. Use point_window when the argument is the logical name of a window. Once a new function is defined, the point_window argument is defined in the Function Generator by using a pointing hand.

“select_list (01)”: The value of the argument is selected from a list. Use select_list when there is a limited number of argument values, and you can supply all the values. Once a new function is defined, the select_list argument is defined in the Function Generator by using a combo box.

“type_edit”:The value of the argument is typed in. Use type_edit when you cannot supply the full range of argument values. Once a new function is defined, the type_edit argument is defined in the Function Generator by typing into an edit field.

  • default_value provides the argument’s default value. You may assign default values to select_list and type_edit arguments. The default value you specify for a select_list argument must be one of the values included in the list. You cannot assign default values to point_window and point_object arguments.

The following are examples of argument definitions that you can include in generator_add_function statements. The examples include the syntax of the argument definitions, their representations in the Function Generator, and a brief description of each definition.

Example

The function_name is window_name. The description is “This function...”. The arg_number is 1. The arg_name is Window Name. The arg_type is point_window. There is no default_value: since the argument is selected by pointing to a window, this argument is an empty string.

When you select the window_name function in the Function Generator and click the Args button, the Function Generator appears as follows:

Function Generator appears
Example

The function_name is state. The description is “This function...”. The arg_number is 1. The arg_name is State. The arg_type is select_list. The default_value is 0.

When you select the state function in the Function Generator and click the Args button, the Function Generator appears as follows:

Function Generator appears
Example

generator_add_function("value","This function...",1,"Value","type_edit","");

The function_name is value. The description is “This function...”. The arg_number is 1. The arg_name is Value. The arg_type is type_edit. There is no default_value.

When you select the value function in the Function Generator and click the Args button, the Function Generator appears as follows:

Function Generator appears
Defining Property Arguments

You can define a function with an argument that uses a Context Sensitive property, such as the label on a pushbutton or the width of a checkbox. In such a case, you cannot define a single default value for the argument. However, you can use the attr_val function to determine the value of a property for the selected window or GUI object. You include the attr_val function in a call to the generator_add_function function.

The attr_val function has the following syntax:

attr_val ( object_name, "property);

  • object_name defines the window or GUI object whose property is returned. It must be identical to the arg_name defined in a previous argument of the generator_add_function function.
  • property can be any property used in Context Sensitive testing, such as height, width, label, or value. You can also specify platform-specific properties such as MSW_class and MSW_id.

You can either define a specific property, or specify a parameter that was defined in a previous argument of the same call to the function, generator_add_function. For an illustration, see example 2, below.

Example

In this example, a function called “check_my_button_label” is added to the Function Generator. This function checks the label of a button.

The “check_my_button_label” function has two arguments. The first is the name of the button. Its selection method is point_object and it therefore has no default value. The second argument is the label property of the button specified, and is a type_edit argument. The attr_val function returns the labelproperty of the selected GUI object as the default value for the property.
Example

The following example adds a function called “check_my_property” to the Function Generator. This function checks the class, label, or active property of an object. The property whose value is returned as the default depends on which property is selected from the list.

generator_add_function ("check_my_property","This function checks an object’s
property.",3,
"object_name", "point_object", " ",
"property", "select_list("class""label""active")", ""class"",
"value:", "type_edit", "attr_val(object_name, property)");

The first three arguments in generator_add_function define the following:

  • the name of the new function (check_my_property).
  • the description appearing in the Description field of the Function Generator. This function checks an object’s property.
  • the number of arguments (3).

The first argument of “check_my_property” determines the object whose property is to be checked. The first parameter of this argument is the object name. Its type is point_object. Consequently, as the null value for the third parameter of the argument indicates, it has no default value.

The second argument is the property to be checked. Its type is select_list. The items in the list appear in parentheses, separated by field separators and in quotation marks. The default value is the class property.

The third argument, value, is a typeedit argument. It calls the attr_val function. This function returns, for the object defined as the function’s first argument, the property that is defined as the second argument (class, label or active).


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

WinRunner Topics