Tutorial: Sending Messages to the Run Results Using Event Handler Code

In this tutorial, you will send a message to the run results using event handler code. This is useful if you want to report the results of a test step operation that are not supported by the standard activity properties.

In this tutorial, you will be sending a message to the run results for a test using File Create and Write to File steps.

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

Prerequisite - create the test steps.

From the Toolbox pane, from the File section, drag a File Create and then a Write to File step to the canvas.

Back to top

Set the input properties for the File Create step.

  1. In the canvas, select the File Create step.
  2. In the Properties pane, open the Input/Checkpoints tab .
  3. In the Value column for the Folder path property, enter C:\Users\<username>\Documents\UFT One. (This is the default folder for OpenText Functional Testing to save tests.)
  4. In the Value column for the File name property, enter My Sample File.

Back to top

Set the input properties for the Write to File Step.

  1. In the canvas, select the Write to File step.
  2. In the Properties pane, open the Input/Checkpoints tab .
  3. In the Value column for the Content property, enter Step succeeded.
  4. In the Value column for the File path property, enter C:\Users\<username>\UFT One\My Sample File. (Note this is a combination of the Folder path and File name properties from the File Create step.)

Back to top

Create an event handler for the Write to File step.

For this test step, you want to send the message to the run results after the test 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

Add event handler code to send a message to the run results.

  1. In the TestUserCode.cs file, find the TODO: Add your code here... section under the FileWriteActivity5_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 args. (with the period). While you type, OpenText Functional Testing displays an autocomplete list. You can use this list if you want to find the args object.

    After you enter the args. object, OpenText Functional Testing displays another autocomplete list.

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

  5. After the Activity object, enter a period (.) character. Another autocomplete list is displayed.
  6. From the autocomplete list, select the Report function and press ENTER:

  7. After the Report function, add a open parenthesis ( character. Note that the text of the Report function changes color.
  8. Inside the parenthesis, enter the following string: "Step Report", (with the comma). This provides the name of the field to add to the run results.
  9. After the Step Report string, enter the following:

    this.FileWriteActivity5.Content+"was added to "+this.FileCreateActivity4.FileName)

    This string takes the Content property from the Write to File activity, and adds it to the File Name property from the File Create activity to provide the string to report in the run results.

  10. After the previous string, enter a close parenthesis ) character and a semicolon (;) character.

    After entering the Report function syntax, your event handler code should look like this:

    args.Activity.Report("Step Report",this.FileWriteActivity5.Content+"was added to "+this.FileCreateActivity4.FileName);
  11. Click Save .

Back to top

Run the test to check if the message is reported to the run results correctly.

  1. In the toolbar, click the Run button .
  2. In the Run dialog box, click Run. OpenText Functional Testing runs the test, using the property values provided, and also sends the specified message from your event handler code to the run results.

    After the test run is complete, you can see the result in the test step's captured data pane in the run results:

Back to top