Forum Discussion

jyothinb's avatar
jyothinb
Contributor
11 years ago

GeneralEvents - OnLogError Event

I need help with "Stopping current Test Item after N-th Error" , It is not working as I want

 

I want my GeneralEvent script to perform below tasks:

1)  After 8 errors stop the current test Item

2) Close the application

3) Launch application

4) Login to application

5) Run the next test Item

 

This is the screen shot of my script

http://screencast.com/t/7wjG1lwS

 

Can you please advise me, because test execution is stopping but not the application is restarting after that.

5 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Verify whether or not your test project is set to "Stop on Error".  go to Project | Properties | Playback and, if it's on, turn off that check flag.



    Also, note that your If/Then statement is using Log.ErrCount for it's parameter.  The ErrCount is a cumulative value.  so, you'll probably hit 8 and have the script stop then... but then every script will stop immediately as soon as it hits an error rather than waiting for 8.  
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Log.ErrCount is a read-only value, I believe.  You can't reset it via script so that's not going to work.  What you probably should do is create your own counter as a project variable that you can increment in the OnLogError handler before your If/Then statement.



    As for why the stuff coming AFTER the Stop Execution is not happening...  I think it's because you are stopping execution.  The OnLogError event handler "interrupts" the Log.Error process.  So, when an error is logged, this takes over.  In fact, Log.ErrCount does not increment until after the error handler completes.  



    So, when you hit that 9th error (Log.ErrCount=8), it hits the Stop Execution call... and then goes on to the next test item.  I tried all this in TC 10.20.  Screenshot below:







    If you want that stuff to be executed on that 9th error, move it all to be BEFORE the Stop Execution call.  That way it will execute as part of the event handler and then Stop Execution will "kill" the current test item and move on to the next one.



    Hope this helps!





  • Yes, I make sure that 'Stop on Error" is off on project properties.



    May be I should reset the Log.ErrorCount value to "zero".



    But, The other issue is after stopping the current test execution, I have a command to run a keyword script to close(terminate) the application and launch the application again. It is not executing those commands.



    Please look at the screenshot of my Eventhandler script to better understand the issue

    http://screencast.com/t/7wjG1lwS



  • Hi Robert, Sometime I am seeing a message 'Recursive call to on log error event" and testcomplete stops running the scripts until manually clicks on 'YES'. 



    Please see the below screencast for the complete message



    http://screencast.com/t/1fISJo19VM



    Please find the  Onlog error event code below




    function GeneralEvents_OnLogError(Sender, LogParams)


    {


      Log["Message"](Project["Variables"]["ErrorCounter"]);  


      Project["Variables"]["ErrorCounter"]++;


      if (Project["Variables"]["ErrorCounter"] >= 8) 


       {    


           Log["Message"](Project["Variables"]["ErrorCounter"]); 


           KeywordTests["Restart_Smoke_Test"]["Run"]();   


           Project["Variables"]["ErrorCounter"] = 0; 


           Log["Message"](Project["Variables"]["ErrorCounter"]);         


           Runner["Stop"](true);


       }


    }