Disabling the postage of certain error messages

Any message in the log can be captured and processed. In this recipe we will consider the following example. When interacting with the Infragistic controls elements in the TestComplete log, there sometimes arises a message Improper command. This message in no way influences the script's performance and only causes an issue when reviewing log entries; this is why we will simply ignore it.

This is a true-to-life example, which is successfully applied in a commercial project.

Tip

To try this example, you can simply create a function with several calls of the Log.Error method. At least one of these calls should contain Improper command text as an error message.

How to do it...

To avoid logging of the Improper command message, it is necessary to perform the following actions:

  1. Create an OnLogError event handler.
  2. Interject the following code into the event handler:
    if(LogParams.MessageText == "Improper command")
    {
      Log.Message("'Improper command' error is ignored");
      LogParams.Locked = true;
    }

    Now, all the errors with the Improper command text will be ignored.

How it works...

The LogParams object contains all the information on the outputted message to the log.

The MessageText parameter contains the text of the message, and the Locked parameter, preset to the true value is blocking the entry of the message to the log. This block only affects the current event, not the others.

Simple ignoring the errors is a not a good practice, this is why we additionally notify in an ordinary message what exactly is being blocked. If, in the future, due to this error, there emerges any technicalities with the control elements, we will be able to spot these issues in the log and thus will be in the know for the root-cause analysis.

Similarly, other events of the log are to be handled (OnLogEvent, OnLogMessage, and so on).

Note

In the earlier versions of TestComplete (up to 7 inclusively), instead of the MessageText property, the Str property was put to use. Their inner workings are the same; however, the Str property (and the StrEx one, corresponding to that of AdditionalText) are now considered as deprecated and are not recommended for use in the new scripts.

See also

  • The process of creation of the event handler is thoroughly dealt with in the Creating event handlers recipe
..................Content has been hidden....................

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