Forum Discussion

frank_vanderstr's avatar
frank_vanderstr
Contributor
10 years ago

Handling Object Not Found Errors via Exceptions

I am trying to add functionality to my test Automation that will be able to catch Object Not Found errors when they occur and execute a reset script of sorts that will help solve the issue.



Unfortunately the Try Catch blocks do not actually catch one of the most unfriendly errors in Automation.



I have tried creating an event handler for this, but I am having trouble understanding how it actually works, and it seems like a bulky and clumsy solution anyways.



Basically I am trying to find out if there is a way I can prevent the script from completely stopping when it cannot find a mapped object and for that error to be caught and some other code executed.



Here is an example of what I would like to do using javascript.



function TestPage(param1, param2) {

  try {

     var testobj = Aliases.MappedName

     testobj.Click();





 } catch(e)



     Log.Message(e.description);

     ResetFunction(e.description)a;



}

3 Replies

  • Alright, so I figured out how to use the event handler, since it wasn't shown how it works in terms of code. I think I was confused as it works from a chain of command perspective, since it wasn't apparant that the system itself would go to your Error function when an errors occurs.



    My new problem is when an object is not found and the event handler is called and my reset code is executed, when it is finished it tries to go right back to where it left off when the error was called. Am I missing something in my event handler to tell the script to not go back where it originally errored?



    My event handler:

    function GeneralEvents_OnLogError(Sender, LogParams)

    {

      Log.Message("Mapping error occured.");

      //Call to reset function

      return -1;

     

     

    }



    Also the wait and exists methods do not really provide the solution I am looking for, since I am trying to catch errors, then reset the site accordingly, and there not be able need for user input to run the next test in the sequence.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Frank,


     


    when it is finished it tries to go right back to where it left off when the error was called


    What next step do you want to perform?


    If you execute test items, you can specify the Stop on error option. Please read the "Test Items Page (Project Editor)" article for details.