Sending a notification e-mail on timeouts

In this recipe we will deal with an example of dispatching an e-mail in case the execution time of any given test exceeds the maximally assigned time frame.

How to do it...

To send an e-mail upon reaching the timeout, it is necessary to follow through these actions:

  1. Create an OnTimeout event handler.
  2. Add the following code into the created handler:
    BuiltIn.SendMail("[email protected]", "example.com",
      "Sender Name", "[email protected]", "Subject", "Body");
  3. Create a function that will work for 62 seconds. For example, as follows:
    function testEmailOnTimeout()
    {
      aqUtils.Delay(62*1000);
    }
  4. Create the test item (right-click on the name of the project and navigate to Edit | Test Items) and set the timeout to be equal to 1 minute as shown in the following screenshot:
    How to do it...
  5. Launch the project for execution (right-click on the name of the project and select the Run menu).

    In the result, as the one-minute timespan goes out, the timeout will trigger the e-mail dispatch.

How it works...

If a timeout has been signified for the test item, as it fires, the corresponding event will be triggered. In our case, as the timeout fires, the e-mail will be sent to the following address: .

We have used 62-seconds timeout because the minimum timeout is 1 minute and our example should work for more than 1 minute. In such cases it's usually better to have some reserve (for example, 2 seconds, as we have here) to avoid casual firing of the events.

It is also a good practice to specify timeouts by multiplying the number of seconds directly in the code (as we have done here), because such constructions are more maintainable in the future.

See also

  • The considered example of dispatching an e-mail does not suit all of the instances. A more universal method is considered in the Sending logs via e-mail recipe in Chapter 6, Logging Capabilities.
  • The process of creation of the event handler is thoroughly dealt with in the Creating event handlers recipe.
  • Test Items creation is described in greater detail in the Creating a test plan for regular runs recipe in Chapter 4, Running Tests.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.183.210