Forum Discussion

SlickRick's avatar
SlickRick
Frequent Contributor
9 days ago

OnLogError EventHandler Not working for app crash

I already know that my question will look odd to many but i have a test where i want to ensure that for a given condition my application would get closed if the user doesn't have specific authorizations.

Basically ill be killing my application in that condition and sometimes testcomplete will detect that the application crashed and therefore give me a "The XXX.exe process crashed." log error.

So i though that for that particular test i would simply add a OnLogError handler and verify this message and for that particular test simply put a warning instead.

This is my Handler:

function TestStopEventControl_OnLogError(Sender, LogParams) {
  
    Log.Message("DEBUG: Inside OnLogError with message: '" + LogParams.MessageText + "' IgnoreVar:" + Project.Variables.ignoreAppCrashError);
  // Check if the error message matches the specific crash string.
  if (LogParams.MessageText == "The XXX.exe process crashed." && Project.Variables.ignoreAppCrashError) {
    // Log a warning to indicate the error was suppressed.
    Log.Warning(LogParams.MessageText);

    // Suppress the error log by marking it as locked.
    LogParams.Locked = true;
  }
}

For all my log errors this code seems to be run since i see my DEBUG message.

However it doesn't work for the LogError im am trying to ignore....


And like i say, for any other error it seems to go inside the handler:

Im guessing those are "native" error and cannot be changed, but in my case it would have been necessary... 

Any ideas?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    An appropriate action would be to close the application as opposed to killing it. TestComplete' Object Browser will see that the app has crashed, and the handler to the app is no longer. As it's not possible to interact with the app, most likely TC will instruct the scripts not to continue (this is just my theory). Hence, LogOnError not being called.

    Refer to https://support.smartbear.com/testcomplete/docs/testing-with/advanced/tracing-critical-errors/index.html

     

    • SlickRick's avatar
      SlickRick
      Frequent Contributor

      Hi all,

      Indeed I agree with all of you. However in that case we do want to kill the application. I cannot really do in the details, but this is a scenario where the application should not run and may be compromised.

      This is what my UI test is supposed to be testing and therefore having that message is actually what we want =D. 

      FYI, im in contact with smartbear support to see if this can be achieved.

  • scot1967's avatar
    scot1967
    Frequent Contributor

    The events do not fire for App crashes unless the test is coded to do so by checking for time outs, dialog windows or other things that indicate the app has crashed.  These events are TestComplete events that fire for various things that TestComplete is set to check for, like log events, overlapping windows or unexpected windows. Using a Try, Catch, Finally in your test script should help.  Then you can perform the actions you need to like checking if the app process exists or some other app object and then predicably and gracefully handle the application state with a consistent code structure. 

    https://support.smartbear.com/testcomplete/docs/reference/events/index.html

    Cool tip for scripts: Using 'Ctrl j' will display a list box of script commands you can select from and TestComplete will add the stub code for what you need. :)

    • SlickRick's avatar
      SlickRick
      Frequent Contributor

      Hi Scot,

      Sadly i already tried the try, catch, finally which was my first attempt at handling this case. The issue is that there is no real thrown errors. Just TestComplete not likely that the app suddenly got killed.

      After further investigation, in our code we are closing using App.Exit but for some reason from time to time TC seems to detect it as a crash. Will continue to investigate.

      Also in the doc it is explicitly mentioned (not sure how i skipped that) that this event wont be handled:
      OnLogError Event | TestComplete Documentation

      So i guess ill have to result to other alternative...

      Ctrl j is indeed a cool tip which i was not aware of!

  • scot1967's avatar
    scot1967
    Frequent Contributor

    I have used this code to check for the state of the app process. 

     

    try
    {
      if(Sys.WaitProcess(appProcessName,1000).Exists)
      {
        throw new error("Error text for the catch");
      }
    }
    catch (error) 
    {
      Log.Error("Error message for log " + error.message);
    }