How Test Complete Handles Unexpected Windows
When you are designing your script and you know that a specific popup will appear on a particular event then you design your script in that way. You handle that using assertions something like below
if window.exist then
But what if, when you are not aware of a popup window which appears suddenly due to an issue/bug/change in functionality. This could be due to many reasons. e.g. you are working on a printer dialog box and the window popup occurs as ‘printer out of paper”, which is an unexpected window.
The way Test Complete handles this situation, is in following sequence
1. Script execution is delayed until expiration of the “Auto-wait timeout” interval set in the project property, playback section.
2. If the unexpected window is still open, TestComplete generates the OnUnexpectedWindow event. You can use this event to perform required action when an unexpected window appears.The event has the following parameters:
Sender: The Event control that processes the event.
Window: Specifies an unexpected window as a Window object.
LogParams: Properties of the LogParams object hold text, priority, color and other attributes of the error message posted to the log.
below is a simple example, which takes the screenshot and changes the message, when an unexpected window appears.
Sub GeneralEvents_OnUnexpectedWindow(Sender, Window, LogParams)
' Posts the image of the whole screen to the test log
Log.Picture Sys.Desktop, "Image of the whole screen"
' Replaces the TestComplete message with your message
LogParams.Str = "My message"
This event can be added to by adding ‘Events’ to your project.
3. 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 and then acts according to the Playback settings:
- If Stop on error is checked, then the run ends at that point.
- If Stop execution is checked in the Unexpected Window section, Stops the execution
Otherwise, any of the four following actions is taken, depending on the settings in the Unexpected window section:
- Click on focused button simulates a click to the window’s default button.
- Press Esc simulates an ESC keypress.
- Press Enter simulates an ENTER keypress.
- Send WM_CLOSE sends the window the normal window-closing message.
- 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