Forum Discussion

ringraham's avatar
ringraham
Contributor
9 years ago

How to trap/catch TestComplete "Stop on Error"

I have a WPF application that has "hidden" buttons along the top, bottom, left, and right of a map. When a user moves their mouse to an edge, these buttons become active. To click one of these, I move the mouse to the edge of the screen by doing a click in a specific area. It then "unhides" the button. I can see it work when I run the script and the button does indeed get pressed as the "new" window appears in the proper location. However, TestComplete seems to think that the control is still hidden, even though the click event worked!?

 

The script stops on the click event with the errors:

The controls is invisible. The action cannot be executed.

The test has stopped because the "Stop on Error" setting is enabled.

 

I still want the stop on "real" errors, but how do I go about ignoring this falsely reported error?

 

Thanks.

 

-Ron

9 Replies

  • Please use this information with extreme caution.

    Our tests are not set to stop on error. We want the test to go to completion no matter what, so I do not know what effect this method will have when TestComplete is set to stop on the error event. It may stop, but not write the error to the log....

     

    We had one message that we determined to be completely bogus. What we did was add some code to the GeneralEvents_OnLogError subroutine to not enter this error into the log. Substitute the error message that you want to suppress in the code below. It might be possible for you to make it Log.Warning when you encounter this message instead of an error by adding that line below....

     

    Sub GeneralEvents_OnLogError(Sender, LogParams)

          If LogParams.MessageText = "The window was destroyed during method execution." Then
                LogParams.Locked = True
          Else
                LogParams.Locked = False

          End If

    End Sub

     

    • Manfred_F's avatar
      Manfred_F
      Regular Contributor

      Hi Ebunny,

      I use a similar approach as You do.

       

      There were two issues to solve:

      1) how to suppress technical errors e. g. arising while TC is synchronizing with the AUT?

      2) how to deal with known application errors and unknown ones?

       

      The approach is:

      1) suppress technical errors in the GeneralEvents_OnLogError event handler

      2) replace the error message by a warning for known errors, and add a prefix to the title ("Known: ")

      3) stop test run on unexpected errors which make it impossible to further execute the test.

       

      My solustion uses a global "ErrorOption" object located in a script extension.

      The properties:

       .Locked (r/w): the error(s) occurring in this section are pure technical ones and shall be suppressed

       .known (r/w): the error to be generated by a checkpoint in a test routine shall be treated as a known one

       .hasError (r/w): an error occurred, a known one or a suppressed one

       .Routine (r/w), the originator for Logging and debugging purposes

      The methods:

       ReportError; used in the GeneralEvents_OnLogError event handler to inform the global option object about an error message having been suppressed or changed to type warning. It sets the .hasError property to true

       Restore; resets .known, .hasError and .Locked to previous values.

       

      There is not only a single one option object, but there is:

      - a basic global one and eventually

      - one or more local ones that work together with the global one.

      This is necessary to lock and unlock correctly in a test routine hierarchy: e.g. lock errors at a certain location in the upmost test routine, but unlock at a certain location in a called routine on level l, but re-lock at a certain location in a called routine on level, and so on.

       

      There are also two constructor routines:

      Function ErrorLock(Routine)

      - creates a new local ErrorOption object and links it to the global one, sets .Locked to True

       

       

      Function ErrorSetKnown(Routine)

      - creates a new local ErrorOption object and links it to the global one, sets .Known to True

       

       

       

      The usage is as follows:

      1) In the system routine, where technical errors can arise, I use (vbs)

      On Error Resume Next  ' optionally

      Set TcErrLock = PVA_0.TcLog.ErrorLock(mcModul & cRoutine)

      .. ' protecte code

      TcErrLock.Restore

      On Error GoTo 0

       

      In some cases, it is required to also use error handling, as runtime errors can result if properties do not deliver the expected object results.

       

      2) In test routines where I expect a known error, I could use

      Set LogError = PVA_0.TcLog.ErrorSetKnown(mcModul & cRoutine)

      .. ' checkpoints, log.Error, etc here

      LogError.Restore

       

      In reality, I do not use this explicitely, because I've got another global helper object for logging, the checkpointList, which does it for me.

       

      Finally, the GeneralEvents_OnLogError event handler queries the global "ErrorOption" object, locks technical errors, replaces known errors by warnings and uses the .ReportError routine to inform the ErrorOption.

       

      Works fine

       

      Kind Regards,

      Manfred

       

       

       

  • While both answers could possibly work, I was hoping for something in code that would allow one to catch an error, such as:

    try{

    ...

    }

    catch (Exception e)

    {

    ... (ignore error)

    }

     

    Most languages have such a construct to catch ANY exception. Is there no such thing in TestCompletes scripting language?

    • EnergizerBunny's avatar
      EnergizerBunny
      Contributor

      None of the original TestComplete scripting languages provide a strong error handling capability. This is not the fault of TestComplete, but a limitation of the script languages.

      The latest version of TestComplete 11.1 now provides Python scripting. It appears that Python supports the try..catch method.

      Unfortunatly all of our existing test scripts are in VBscript. We might try a new project in Python.

       

      We used to use TestPartner as a test tool until MicroFocus retired it.. It used VBA and had a very strong global on error handler. 

      • Manfred_F's avatar
        Manfred_F
        Regular Contributor

        The ability to apply VBA or VB would be an enormous advantage, not only concerning error handling.

         

        VB/A is typesafe and gives You an error message for undeclared variables or typos BEFORE running the code. Using vbs in TC, I find my typos at runtime instead, which is minutes or even hours later :-((