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.
To avoid logging of the Improper command message, it is necessary to perform the following actions:
OnLogError
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.
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).
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.