Forum Discussion

JeanL's avatar
JeanL
Contributor
14 years ago

Set StopOnError in script

Hello,



Is there any other way to set the value of StopOnError in script than Project.TestItems.Current.StopOnError = 0.



This isn't working if I run a subroutine without creating testitem (e.g. I use Run Current Routine).



I would like to do Regions.Items(region).Check in loop few times before stopping the execution. So I don't want that the execution stops in first check if it's not true. I don't want to turn errors off completely. I could use Log.Enabled = false, but then I don't get the log messages wheter the check has succeeded or not.



I would use Regions.Compare method where I can specify the failure message type, but with that method I can't use masks.







Edit. I just realized that I can't use Project.TestItems.Current.StopOnError method to set the value. But the question still remains, is there a way to do this?
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Jean,


    Unfortunately, there is no way to do exactly what you need. So, there are two approaches that may help:


    1. Create a test item for your routine and specify the value of the StopOnError property for this project item from script.


    2. Disable the Stop on error project option manually before running the test.


    For more information, please refer to the Stopping Tests on Errors and Exceptions help topic.

  • amit_deshpande's avatar
    amit_deshpande
    Occasional Contributor
    Hi Jean,



    The use of events and event handlers can be customized in your case. You may try the following steps to achieve what you want -



    1.Have customized error message at a point where you want to stop or after the check which upon failure the test should be stopped.

    2.Enable events

    3.From general events, select onLogError event and add event handler/listner to it.

    4.In event handler/listener function check for the customized message if posted in the logs. If that is found in logs stop the test by Runner.Stop() else come out of function.



    I have used this method in my tests and it works.



    -Amit