cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected window eventhandler activation

SOLVED
Occasional Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Unexpected window eventhandler activation

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();

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
2 REPLIES 2
Community Hero

Re: Unexpected window eventhandler activation

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();

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Community Manager

Re: Unexpected window eventhandler activation

@AlexKaras, thanks for such a detailed explanation!

 

@JohnSnikers, have you found the answer to your question? Please share it with us.

---------
Tanya Gorbunova
SmartBear Community Manager

Join the September Hub-bub to show off, learn and win
New Here?
Join us and watch the welcome video:
Join the September Hub-bub to show off, learn and win