Forum Discussion
AlexKaras
12 years agoChampion Level 3
Hi Hugo,
The essence of the OnUnexpectedWindow event (likewise for the OnOverlappingWindow one) is that it can be triggered only if your script tries to perform some action over the target window. I.e. if the script tries to either click something within the window, or set the focus to some control/activate the window or type something via the .Keys() method.
The event will not be triggered if the window is operated by the methods that do not require 'direct' interaction with that window. I.e. commands like window.Close, window.control.setText, etc. will not trigger OnUnexpectedWindow event even if the target window cannot be focused because of the overlapping modal window.
Considering the above, you have two options to prevent endless recursion in the event handler (BTW, TestComplete is quite smart and pretty often will either warn you or stop the test with the relevant message in the test log if the test code enters endless recursion in the event handler):
a) You can operate with the unexpected windows via the methods that do not require emulation of mouse clicks or key presses;
b) You can introduce a public flag variable of boolean type and use it to prevent recursion. Something like this (untested DelphiScript pseudocode):
var boolInHandler;
procedure OnStartTest()
begin
boolInHandler := false;
...
end;
procedure OnUnexpectedWindow()
begin
if (boolInHandler)
return;
try
boolInHandler := true;
...
finally
boolInHandler := false;
end;
...
end;
The essence of the OnUnexpectedWindow event (likewise for the OnOverlappingWindow one) is that it can be triggered only if your script tries to perform some action over the target window. I.e. if the script tries to either click something within the window, or set the focus to some control/activate the window or type something via the .Keys() method.
The event will not be triggered if the window is operated by the methods that do not require 'direct' interaction with that window. I.e. commands like window.Close, window.control.setText, etc. will not trigger OnUnexpectedWindow event even if the target window cannot be focused because of the overlapping modal window.
Considering the above, you have two options to prevent endless recursion in the event handler (BTW, TestComplete is quite smart and pretty often will either warn you or stop the test with the relevant message in the test log if the test code enters endless recursion in the event handler):
a) You can operate with the unexpected windows via the methods that do not require emulation of mouse clicks or key presses;
b) You can introduce a public flag variable of boolean type and use it to prevent recursion. Something like this (untested DelphiScript pseudocode):
var boolInHandler;
procedure OnStartTest()
begin
boolInHandler := false;
...
end;
procedure OnUnexpectedWindow()
begin
if (boolInHandler)
return;
try
boolInHandler := true;
...
finally
boolInHandler := false;
end;
...
end;
Related Content
- 2 years ago
- 4 years ago
- 6 years ago
- 7 years ago
Recent Discussions
- 17 hours ago