TestComplete allows you to retrieve the number of errors for the current test item (with the help of the Log.ErrCount
property); however, there is no way of finding out the total number of errors in all the executed tests. Such a possibility can be useful only if a certain predefined number of errors is treated as critical, upon reaching which test execution should be stopped altogether.
First of all, we will add two new variables on the level of Project Suite as follows:
ErrorsTotal
variable, into the field Type select Integer
, and set the Default Value field to 0
.This variable will be a counter of the errors.
ErrorsMax
. As Default Value, set the number of errors which should signal stopping test execution (in our example, those are equal to 3
).In the result, we will have two new variables created, as shown in the following screenshot:
OnLogError
event, which will increase the counter of the errors. For this purpose, perform the following steps:Events
element to the project, if it is still missing (right-click on the name of the project and navigate to Add | New Item | Events).OnLogError
.OnLogError
element.GeneralEvents_OnLogError
.function GeneralEvents_OnLogError(Sender, LogParams) { ProjectSuite.Variables.ErrorsTotal += 1; if(ProjectSuite.Variables.ErrorsTotal > ProjectSuite.Variables.ErrorsMax) { Runner.Stop(); } }
function testErrorsCount() { for(var i = 0; i < 10; i++) { Log.Error("Error #" + i); } }
testErrorsCount
function now we would see that upon the fourth emergent error, test execution would be stopped, since the number of arisen errors exceeded the preset value of the ErrorsMax
variable.In the OnLogError
events handler, we increase the number of emerging errors each time the error is generated in the log (no matter how: either with the help of the method Log.Error
or via TestComplete in itself, the event will be processed all the time).
When the number of errors exceed the preset threshold, we stop execution of the tests with the help of the Runner.Stop
method.
To the variables on the level of Project Suite there exists access from any project. Therefore it is unimportant how exactly tests are launched: from the Project Suite, or just a project or several separate functions. In any case, the variable will be updated each time an error occurs.
It's worthwhile to note, if you have several projects running in Project Suite, each one of them should contain some sort of handler. To this end, it is much easier to create such a handler in one project and in the other projects add an existing module (by right-clicking on the Script
element, thus opting for the Existing Item menu item in the Add menu). This allows us to avoid code duplication.
In the same manner, one could trace the number of other messages (Event, Warning, File, and so on), since for each of them there exists a corresponding property, containing their number in the current test item (Log.EvnCount
, Log.WrnCount
, Log.FileCount
, and so on).
18.188.154.252