Test Object Method Function      

Description

Simulates an action on a Web page.

Syntax

function <operation>(<parameters>)

Return Value

true on success, otherwise false.

Remarks
  • The test object method signature must match the definition of the operation in the test object configuration file.
  • By default, the name of the function is the same as the name of the test object operation is implements. You can specify a different function name in the toolkit configuration file. For example:

<Control>

    <Run>

        <Methods>

            <Method name="SetUsername"

                        type="javascript" function="PerformSetUsername"/>

        </Methods>

    </Run>

</Control>

  • The signature must match the steps written during recording using _util.Record.
  • For example, if there is a call:
    _util.Record("SetUserName", toSafeArray("foo"), 0)
    then the function that implements the SetUserName operation must accept one text argument.

  • When simulating a mouse event to perform an operation on a control, the test object method can use predefined mouse-button constants to specify the button performing the operation.
  • Use these constants (without quotes) or values (defined in the common.js file):

    Constant

    Value

    QtpConstants.LEFT_BUTTON
    0
    QtpConstants.MIDDLE_BUTTON
    1
    QtpConstants.RIGHT_BUTTON
    2
Status Reporting

A test object method should report on the completion status of the operation. There are number of symbolic constants you can use to report execution status in your operations functions. They are:

micPass (0) - Causes the status of this step to be passed and sends the specified message to the run results. Use this code only if your method actually checks that the action succeeded at the application level. Normally, this code is used only by UFT.

micFail (1) - Causes the status of this step to be failed and sends the specified message to the run results. When this step runs, the test or component fails. Use this code to indicate that the method failed to run as expected.

micDone (2) - Sends a message to the run results without affecting the pass/fail status of the test or component. Use this code to indicate that the method ran to completion. This is the most common code to use in a test object function.

micWarning(3) - Sends a warning message to the run results, but does not cause the test or component to stop running, and does not affect the pass/fail status of the test or component.

For example:

_util.Report(micDone, "Set", toSafeArray(new Array(state));

Example

This example sets the text in a text field.

function SetUsername(text)

{

    // When clearing the text in the text area we get NULL or empty string.

    // Converting both to empty string.

    _elem.innerHTML = text != null? text: "";

    return true;

}