Forum Discussion

JohnSnikers's avatar
JohnSnikers
Occasional Contributor
6 years ago
Solved

Unexpected window eventhandler activation

Hi,

 

There are many different unexpected windows in my TestApplication so I created an Unexpected Window Event Handler to be able to handle all of them.

(Different texts, buttons and have to handle most of them differently, for instance sometimes press buttonYes or press buttonNo)

But the problem is it won't run after each action for example there are scenarios where

function sample(){

Menu.Click("Main menu");

--Unexpected window--

testapp.menuMain.Close();

}

And it can't handle the unexpected window or if it can, then the .Close action won't be executed.

Or 

function sample(){

Menu.Click("Main menu"); testapp.menuMain.Close(); --Unexpected window-- Menu.Click("Other menu");

}

In this case if the unexpected window will be closed, then the Menu.Click("Other menu"); won't be executed.

 

So the question is how to create a proper unexpected window handler which runs/is active between each action without any hardcoding in the sample function.

 

Please help me understand the problem and not just link the documentation about how to create eventhandlers.. I already read it.

Thank you

  • Hi,

     

    > link the documentation about how to create eventhandlers.. I already read it.

    Fine. This makes me think that setup actions have been done and done correctly.

    TestComplete treats some window as unexpected one if this window blocks action to be done over some other window.

    Windows that are considered to be unexpected are usually system or application modal ones that make it not possible to activate another window of the tested application until this modal window is closed.

    Note, that window is considered to be unexpected only if it has blocked some action over another window of the same application. Otherwise there is no criterion to decide if the just opened window is unexpected or not.

    The generic approach for unexpected windows:

    -- Call .Activate() method for the window. Window activation (put on top of all other windows of the tested application) will fail if this window is overlapped by some other modal window and this will trigger OnUnexpected event;

    -- Controls on the form do not have .Activate() method but they have .SetFocus() one.

     

    Note, that if you do not perform activation/focusing actions over the form/control but manipulate it via its other methods/properties that do not perform activation, the OnUnexpected event will not be triggered even if the target window/control cannot get input focus. For example, this line of code will not trigger the OnUnexpected event because it operates directly against object's property:

    myApp.LoginForm.UserName.Value = 'John';

     

    > testapp.menuMain.Close();

    When you close the tested application, the OnUnexpected event will not be triggered because as a rule you do not activate any other window. In this case you need to wait in a loop until the process of the tested application ends (within some reasonable timeout) and check if some window appears on thescreen and close it if it does. (Yes, you must know what windows might be shown on application close.)

    Something like this (pseudocode):

    do {

      if (app.WaitChild('CrashWindow1', 500).Exists)

        ' handle CrashWindow1;

     

      if (app.WaitChild('CrashWindow2', 500).Exists)

        ' handle CrashWindow2;

     

      Delay(500);

    } until app.Exists();

     

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > link the documentation about how to create eventhandlers.. I already read it.

    Fine. This makes me think that setup actions have been done and done correctly.

    TestComplete treats some window as unexpected one if this window blocks action to be done over some other window.

    Windows that are considered to be unexpected are usually system or application modal ones that make it not possible to activate another window of the tested application until this modal window is closed.

    Note, that window is considered to be unexpected only if it has blocked some action over another window of the same application. Otherwise there is no criterion to decide if the just opened window is unexpected or not.

    The generic approach for unexpected windows:

    -- Call .Activate() method for the window. Window activation (put on top of all other windows of the tested application) will fail if this window is overlapped by some other modal window and this will trigger OnUnexpected event;

    -- Controls on the form do not have .Activate() method but they have .SetFocus() one.

     

    Note, that if you do not perform activation/focusing actions over the form/control but manipulate it via its other methods/properties that do not perform activation, the OnUnexpected event will not be triggered even if the target window/control cannot get input focus. For example, this line of code will not trigger the OnUnexpected event because it operates directly against object's property:

    myApp.LoginForm.UserName.Value = 'John';

     

    > testapp.menuMain.Close();

    When you close the tested application, the OnUnexpected event will not be triggered because as a rule you do not activate any other window. In this case you need to wait in a loop until the process of the tested application ends (within some reasonable timeout) and check if some window appears on thescreen and close it if it does. (Yes, you must know what windows might be shown on application close.)

    Something like this (pseudocode):

    do {

      if (app.WaitChild('CrashWindow1', 500).Exists)

        ' handle CrashWindow1;

     

      if (app.WaitChild('CrashWindow2', 500).Exists)

        ' handle CrashWindow2;

     

      Delay(500);

    } until app.Exists();