Tutorial: Viewing the Run-Time Value of a Property During a Test Run Using Event Handler Code

In this tutorial, you will send a message to the output log using event handler code. This can be useful if you want to watch the value of a specific property during the test run to help you isoloate or debug problems in your application.

In this tutorial, you will be watching the output value of a Concatenate Strings step.

Note: We recommend printing this topic or putting the browser window on a second screen before performing this tutorial in a sample API test.

  1. Prerequisite - create a Concatenate String step

    If necessary, from the String Manipulation section of the Toolbox pane, drag a Concatenate Strings step to the canvas.

    Back to top

  2. Enter the input properties for the Concatenate Strings step.

    1. In the Properties pane, open the Input/Checkpoints tab .
    2. In the Input/Checkpoints tab, enter the following input properties:

      Prefix Hello (with a space after Hello)
      Suffix World.

    Back to top

  3. Create an event handler for the Concatenate Strings step.

    For this test step, you want to watch the value of the output property after the step runs, so it is important to select the event handler that runs after the test step.

    1. In the Properties pane, select the Events tab .
    2. In the Events tab, in the AfterExecuteStepEvent row, click the down arrow and select Create a default handler.

      A separate tab, titled TestUserCode.cs, opens in the document pane, and a section of code is added to this file for the AfterExecuteStepEvent section.

    Back to top

  4. Add event handler code to specify the property to watch.

    1. In the TestUserCode.cs tab, find the TODO: Add your code here... section under the ConcatenateStringsActivity<#>_OnAfterExecuteStepEvent portion of the code.
    2. Delete the //TODO: Add your code here... string.

      Note: Make sure not to delete the brackets on the line above and below the TODO line. These brackets are needed for proper code syntax.

    3. In the same line, enter Context. (with the period). (While you type, UFT displays an autocomplete list. You can use this list if you want to find the Context object.)

      After you type the Context object, UFT displays another autocomplete list.

    4. From the autocomplete list, select the UserLogger object:

    5. After the UserLogger object, type a period (.) character. Another autocomplete list is displayed.
    6. From the autocomplete list, select Info and press ENTER:

    7. After the Info function, add a open parenthesis ( character. Note that the text of the Info function changes color.
    8. Inside the parenthesis, add the following string:

      this.ConcatenateStringsActivity<#>.Result

      This string enables you to retrieve the value of the Result property from the Concatenate Strings step.

    9. After the Result string, enter a close parenthesis ) character and a semicolon (;) character.

      Your event handler code should now look like this:

      Context.UserLogger.Info(this.ConcatenateStringsActivity<#>.Result);
    10. Click Save .

    Back to top

  5. Run the test to see the property run-time value.

    1. In the toolbar, click the Run button .
    2. In the Run dialog box, click Run. UFT runs the test, using the property values provided, and also reports the run-time value of the Result property to the User Logger log in the Output pane:

    Back to top