When recording a test, you define the expected behavior of your application under test. At playback, unexpected situations can occur, like a modal window that displays a message about an assertion or an error from the OS or another application window may overlap the point where a mouse click should be simulated.
Note: | Currently, TestComplete does not handle unexpected windows if they are implemented as windowless objects (see below). TestComplete only checks for unexpected windows when the test performs an action ( |
The window that impedes the running of the test can be modal or non-modal. A non-modal window is not an issue, since the operating system neither requires non-modal windows to have an input focus nor be closed before working with other windows. To bypass these windows during playback, enable the On overlapping window > Ignore overlapping window property of your project. TestComplete also generates the OnOverlappingWindow
event, which allows you to perform specific actions for non-modal overlapping windows.
If the window is modal, the operating system is not able to switch to other windows until this window is closed. TestComplete handles these windows automatically through a preset sequence. One important step in the sequence, “what does the test do now?”, is defined by you in the Playback section of your project properties. The sequence is as follows:
-
TestComplete waits for the unexpected window to close until the Auto-wait timeout set for your project expires.
-
If the unexpected window is still open, TestComplete generates the
OnUnexpectedWindow
event. -
If the window is not closed by the
OnUnexpectedWindow
event handler, TestComplete posts an error message to the log along with an image of the unexpected window. Then it performs the following:-
If the current test is run as a test item and its On error property is set to Stop current item or to Stop project, the test run stops.
If the current test is run as a standalone test (for example, from the Project Explorer) and your project’s On error property is set to Stop current item or to Stop project, the run ends.
-
If the On unexpected window > Stop execution property of your project is enabled, the test run ends. (The difference between the On error and Stop execution properties is that the former stops the test run when any error occurs, while the latter stops the run only when an unexpected window appears.)
-
Otherwise, depending on the settings set in the On unexpected window section of your project, any of the following actions is taken:
-
The test engine tries to simulate a click on the control currently focused in the window.
-
The test engine simulates pressing the Esc key.
-
The test engine simulates pressing the Enter key.
-
The test engine sends the close command to the window.
-
-
-
If the window is still not closed (which may occur if you do not have a closing-action checked, or if the closing action(s) failed), the run ends.
When an unexpected window appears, TestComplete saves its image and posts an error message to the test log. If you need to perform specific actions, like saving the whole screen as an image, or launching a keyword test, you can use the event handler of the OnUnexpectedWindow
event. See Handling Events and Creating Event Handlers for TestComplete Events for more information. Note that if you simulate a mouse click within the OnUnexpectedWindow
or OnOverlappingWindow
event handler, TestComplete will check for an unexpected window recursively.
Remarks
Currently, TestComplete does not handle the following window types as unexpected:
-
Modal windows and dialogs implemented as windowless objects. That includes:
-
Modal windows in Flex applications (for example, those created using the
PopUpManager
class). -
Modal windows in web applications (for example, those created using the
div
element or JavaScript). -
ActionScript errors displayed by Flash Player.
-
Forms in mobile applications.
-
-
Unexpected windows in Delphi and C++Builder CLX applications. This is due to specifics of the CLX library implementation: an application’s window can be activated even when a modal dialog is displayed. Because of this behavior, TestComplete does not treat modal CLX windows as unexpected ones.
To handle windows of these types as unexpected, use the WaitWindow
or FindChild
method to check if a modal window appears after your test performs actions that can lead to this. The following code snippet demonstrates this:
JavaScript, JScript
function Test()
{
var p, unexpWnd;
p = Sys.Process("MyApplication");
// Do something
...
// Handle possible unexpected window
unexpWnd = p.WaitWindow("QWidget", "Error", -1, 1000);
if (unexpWnd.Exists)
{
// Post the window image to the log
Log.Picture(unexpWnd.Picture(), "Unexpected window detected.");
// Close unexpected window
unexpWnd.Close();
}
// Continue testing
...
}
Python
def Test():
p = Sys.Process("MyApplication")
# Do something
...
# Handle possible unexpected window
unexpWnd = p.WaitWindow("QWidget", "Error", -1, 1000)
if unexpWnd.Exists:
# Post the window image to the log
Log.Picture(unexpWnd.Picture(), "Unexpected window detected.")
# Close unexpected window
unexpWnd.Close()
# Continue testing
...
VBScript
Sub Test
Dim p, unexpWnd
Set p = Sys.Process("MyApplication")
' Do something
...
' Handle possible unexpected window
Set unexpWnd = p.WaitWindow("QWidget", "Error", -1, 1000)
If unexpWnd.Exists Then
' Post the window image to the log
Call Log.Picture(unexpWnd.Picture, "Unexpected window detected.")
' Close unexpected window
unexpWnd.Close
End If
' Continue testing
...
End Sub
DelphiScript
procedure Test;
var p, unexpWnd;
begin
p := Sys.Process('MyApplication');
// Do something
...
// Handle possible unexpected window
unexpWnd := p.WaitWindow('QWidget', 'Error', -1, 1000);
if unexpWnd.Exists then
begin
// Post the window image to the log
Log.Picture(unexpWnd.Picture, 'Unexpected window detected.');
// Close unexpected window
unexpWnd.Close;
end;
// Continue testing
...
end;
C++Script, C#Script
function Test()
{
var p, unexpWnd;
p = Sys["Process"]("MyApplication");
// Do something
...
// Handle possible unexpected window
unexpWnd = p["WaitWindow"]("QWidget", "Error", -1, 1000);
if (unexpWnd["Exists"])
{
// Post the window image to the log
Log["Picture"](unexpWnd["Picture"](), "Unexpected window detected.");
// Close unexpected window
unexpWnd["Close"]();
}
// Continue testing
...
}
See Also
Handling Events
Creating Event Handlers for TestComplete Events
OnUnexpectedWindow Event
OnOverlappingWindow Event
Testing Modal Windows