Supporting Dynamic Lists of Values for Method Arguments

When a UFT One user creates a test step with a test object method, UFT One can display a set of predefined possible values available for the arguments of that method. For example, if an argument is a Boolean argument, UFT One can display true and false as the possible values, or, for a month argument, UFT One can display a list of names of all the months. However, sometimes, a limited set of possible values for an argument exists, but depends on the specific object on which the step is performed. For example:

  • The values that are actually relevant for the Integer row and column arguments of the function Table(<table_name>).SetCellData (row, column) are limited to the number of rows and columns in the specific table.

  • The relevant values for the String path argument of the function Tree(<tree_name>).Select (path) are limited to the paths that exist in the specific tree.

Using extensibility, you can enable UFT One to dynamically provide a list of values for arguments of test object methods. UFT One provides this list only in the Editor, when the statement completion feature is used.

To support a dynamic list of values:

  1. In the test object configuration file, set the DynamicListOfValues attribute of the Argument element to true.

  2. In the toolkit configuration file, you can specify the file name and function name of the JavaScript function that UFT One must call to retrieve the list of values. By default, UFT One requests the list of values by calling the get_list_of_values JavaScript function from the default implementation file that you specify for the test object class in the default_imp_file variable in the Control\Settings element. For more information, see the Toolkit Configuration Schema Help.

    UFT One calls the JavaScript function for every argument whose DynamicListOfValues attribute is set to true in the test object configuration file. The parameters provided to this function indicate the test object method and argument for which the values are being requested.

  3. Write a JavaScript function that accepts the names of the test object method and argument and returns a list of values relevant for the specified argument on the current element. Return the string values concatenated to one string, each value enclosed in quotation marks.

    Note: The dynamic list of values is retrieved from the control in the application being tested. Therefore, to display the dynamic list of values, the relevant control must be visible in the application when the test is edited.

For example, in the toolkit support set for the WebExtSample environment, located in <Web_Add-in_Extensibility_SDK_installdir>\samples\WebExtSample folder, a dynamic list of values is supported for the AuthorName argument in the GoToAuthorPage test object method of the test object class WebExtBook.

  • In the WebExtSampleTestObjects.xml test object configuration file, the argument is defined as follows:

    <Operation Name="GoToAuthorPage" PropertyType="Method">
        <Description>
            Opens the Web page for the specified author.
        </Description>
        <Argument Name="AuthorName" IsMandatory="true" Direction="In" 
                  DynamicListOfValues="true">
            <Type VariantType="String"/>
            <Description>The author.</Description>
        </Argument>
    </Operation>
    
  • In the WebExtBook.js file (defined as the default implementation file for the WebExtBook test object class in the WebExtSample.xml toolkit configuration file) the following JavaScript functions are designed to return a list of the book's authors, each enclosed in quotation marks:

    // Dynamic list of values implementation
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    function get_list_of_values( method, argIndex )
    {
        // When creating a step with the GoToAuthorPage test object
        // method, provide a list of the authors of this book, that 
        // can be used for the method's argument.
        if (method == "GoToAuthorPage")
        {
            return get_GoToAuthorPage_list_of_values(argIndex);
        }
        return null;
    }
    function get_GoToAuthorPage_list_of_values(argIndex)
    {
        var arr = new Array();
        if( argIndex > 1 )
            return toSafeArray(arr);
        // Retrieve all authors
        var AuthorsCount = 0;
        var authors = window._uft.$(_elem.rows[1].cells[0]).children("A");    
        for( var i = 0 ; i < authors.length ; ++i )
        {
            arr[AuthorsCount] = "\"" + authors.eq(i).text() + "\"";
            AuthorsCount++;
        }
        return toSafeArray(arr);
    }
    

    Note: The _uft.$ indicates that this code uses an isolated jQuery JavaScript function library to provide browser-independent support.

    UFT 14.50 and earlier

    If your toolkit was developed using a UFT version of 14.50 or earlier, the jQuery library is called using only $.

    If errors occur due to conflicting jQuery libraries, we recommend you upgrade your toolkit using UFT 14.51 or later.