Forum Discussion

gus's avatar
gus
Contributor
10 years ago
Solved

GeneralEvents_OnUnexpectedWindow not invoked?

 Hi, I seem to have some problem with unexpected window handling—in short, TC does not invoke my GeneralEvents_OnUnexpectedWindow event handler.

 

I have included a screenshot showing part of my keyword test, and here's what happening:

  1. Steps before the green mark 1 perform a click action on a button to open a (modal) window.
  2. Since opening the window includes some preparational steps of greatly varied length, I've added an If Object statement to wait for the text field I want to type in.
  3. This is just a message of debugging purpose, confirming test execution passes step 2.
  4. When performing this step, I receive a The object does not exist error. Note that this step is targeted at the very same object the existence of which is checked in step 2.

 

UnexpectedWindow-TestSteps.png

 

Since the message in step 3 appears in the test log, and step 4 generates an error, the unexpected window must be opened after step 3. I have a GeneralEvents_OnUnexpectedWindow event handler which closes the window, however this event handler is not called at all (no breakpoints are hit in it, no the log message included in the first line of the event handler's body displays in the log).

 

When I first read about handling unexpected windows in TC, I thought this is a very typical situation when it should work so that I can close the window.

 

Can you help me what may I do wrong and how to fix it to have my event handler invoked?

  • Hi,

     

    The OnUnexpectedWindow event is triggered only when TestComplete tries to perform some action over the tested application and this action is blocked by the modal window. That is, if your test code tries to .Activate, or .Click, or .Keys over some tested object and this is blocked by some other modal window, the OnUnexpectedWindow event will be triggered.

    Your code does not perform any UI-related actions (.SetText calls internal methods unlike the mentioned .Keys method) and thus the OnUnexpectedWindow is not triggered.

3 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    The OnUnexpectedWindow event is triggered only when TestComplete tries to perform some action over the tested application and this action is blocked by the modal window. That is, if your test code tries to .Activate, or .Click, or .Keys over some tested object and this is blocked by some other modal window, the OnUnexpectedWindow event will be triggered.

    Your code does not perform any UI-related actions (.SetText calls internal methods unlike the mentioned .Keys method) and thus the OnUnexpectedWindow is not triggered.

  • do you need to add the handler to GeneralEvents - maybe you have already done this?

    • gus's avatar
      gus
      Contributor

      Hi Tony,

       

      Yes, I did. It's code reads:

       

      function GeneralEvents_OnUnexpectedWindow(Sender, Window, LogParams)
      {
        Log.AppendFolder("Unexpected window titled " + Window.WndCaption + " encountered");
        if (Window == Aliases.Foo.dlgFooLocalization) { // The localization window of the debug build    
          Window.Close();
          Log.Message("It was the localization window, and was closed successfully.");
        }  
        Log.PopLogFolder();
      }

       

      None of these log messages can be found in the log, however.