Forum Discussion

JBO's avatar
JBO
New Contributor
7 years ago

OnLogError Eventhandler always fires before OnTimeout

I have two Eventhandler, one for timeout and the other one for Errors. For some reason I can't get into the Timeout Eventhandler as the OnLogError always fires in case of timeout and for some reason in that case no Error is set and the Script appears passed(green).

 

This are the two Event handler procedures in delphiscript:

1. OnLogError:

procedure umgebungSetzenbeiFehler (Sender;LogParams);
begin
  Log.Message('Eventhandler Stop: Testfall wegen Fehler abgebrochen');
  Runner.Stop(true);
end;

 

2. OnTimeout:

procedure GeneralEvents_OnTimeout(Sender; Params);
begin
  Log. message('Der Test ist wegen Timeout abgebrochen');
  Runner.Stop(true);
end;

 

If I remove the Runner.Stop(true) from the OnLogError Eventhandler I get into the Timeout. The problem is that I need the Runner.Stop(true) to stop the test item in case of an error.

 

Is there any solution for this? I think in case of a timeout the OnLogError event shouldn't fire.

 

  • As soon as the logic of TestComplete goes to write an error to the log, OnLogError fires.  Since a Timeout is an error, the error event handler fires first as that is what happens first.

     

    If you prefer the timeout to fire your Runner.Stop, what I would do is add code to your OnLogError event handler to check the contents of the error text being written.  If it contains the text associated with a timeout, skip the handler code.

     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    As soon as the logic of TestComplete goes to write an error to the log, OnLogError fires.  Since a Timeout is an error, the error event handler fires first as that is what happens first.

     

    If you prefer the timeout to fire your Runner.Stop, what I would do is add code to your OnLogError event handler to check the contents of the error text being written.  If it contains the text associated with a timeout, skip the handler code.

     

  • JBO's avatar
    JBO
    New Contributor

    For now I skipped the Runner.Stop in  the OnLogError in case of a Timeout.

     

    Let's see how it work. Thanks Robert!

  • JBO's avatar
    JBO
    New Contributor

    Robert,

     

    thanks for the answer. I am fine if the OnLogError raises the error, but in case of the timeout it runs into the OnLogError, does the Runner.Stop(true), but the test item appears green with status success. I would expect that the status would be Error in that case.

     

    Any idea why this is the case? 

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Because Runner.Stop(true) is called within the handler, the writing the error to the log never executes.  Basically, what's happening is that the handler is 'interrupting" the process of logging the error to give the code the opportunity to do something different if you want.  

       

      Now, you don't want to call Log.Error in the middle of the OnLogError event handler... that will just put stuff into an infinite iterative loop.  If you want your test item to stop on an error, there's a better way of doing so than putting Runner.Stop in the event handler. See the below screenshot.  With this setting, the indicated test item will stop on logging any error.  Because it's set to "Test Item", it will continue to execute any additional test items in the project, stopping only the current on.