Forum Discussion

merusso's avatar
merusso
New Contributor
15 years ago

Why don't TestComplete's Test Objects/Methods/Parameters Throw Exceptions?

Sorry if I'm in the wrong place.  I'm currently evaluating TestComplete as a possible replacement of our current test automation tool, and I'm trying to see if it either contains similar behavior to our current tool or if it can offer similar testing with alternative methods.



The thing I'm stuck on right now is that TestComplete can use a more modern object-oriented scripting language (compared to proprietary languages or VBScript) with support for exception handling, but for some reason, TestComplete's methods don't throw exceptions.



Without this capability, I can't see how exceptions can propagate up the call stack.



For example, FunctionA() calls FunctionB(), which tries to click on an object that it can't find.  If "try catch" is set up in FunctionA(), it will know if standard JScript exceptions occur in FunctionB(), but it cannot know if errors result from TestComplete methods.  It seems like the only options are to halt the test (useless to me), break the call chain and always execute FunctionC(), or continue execution.



I want to be able to detect when these errors occur and throw them.  Is there any way to do this?


3 Replies


  • Hello Michael,





    To accomplish your task, you should handle the OnLogError event. 

    There is a quote from the Catch Operation help topic:







    Note that the Try and Catch operations only handle exceptions raised by the test engine, like an incorrect number of parameters specified for a test operation or incorrect parameter types, syntax errors in code expressions embedded in the test and others. They do not handle errors that are posted to the test log by TestComplete’s test objects, methods and properties, like “Object not found”, “Object does not support this property or method” and the like. To handle these errors, create an event handler for the OnLogError event (see About Events and Event Handling ).







    Also, see the Creating an Event Handler for the OnLogError Event help topic.
  • merusso's avatar
    merusso
    New Contributor
    Thanks for the response.



    I saw that quote in the Try/Catch documentation about not catching errors in TestComplete methods, and without it, I would've simply assumed that I was doing something wrong or there was a bug.



    The problem, from my understanding, with the "create an event handler" approach is that the script directly calling the TestComplete methods can't detect if an error occurred in the TestComplete method and handle or throw it.



    If you create an event handler for onLogError, the script simply jumps to the onLogError function and executes from there.  The call chain is lost, if I'm not mistaken.



    So the solution seems to be to perform a check (like check if an object exists, and that it supports the given method, and any other possible errors that could occur) before calling a TestComplete method, and if those checks fail, throw an exception.



    Again, it could be that I'm new.  Maybe errors occurring in TestComplete methods should always signal a test failure worthy of breaking the call chain.  I just have used a different methodology for test script creation in the past where the calling actions were always the first responsible party for handling errors of that nature.



  • Hello Michael,





    If I understand your problem correctly, you need to handle the "Object does not exist" error of some particular objects in specific parts of your tests in a special way. The solution is to check if the object exists before accessing its properties. TestComplete allows you to accomplish such tasks using various Wait* methods as described in the following help topic: Checking Whether an Object Exists.