OnUnexpectedWindow Event

Applies to TestComplete 15.20, last modified on January 19, 2022

Occurs when an unexpected window appears.

Declaration

OnUnexpectedWindow(SenderWindowLogParams) Parameters
Sender [in] Required Variant
Window [in] Required An OnscreenObject object
LogParams [in] Required A LogParams object

Description

When an unexpected window appears during the script execution, TestComplete posts an image of this window and an error message to the test log. Before posting the image and message, it generates the OnUnexpectedWindow event.

You can use this event to perform specific actions when an unexpected window appears. For instance, you can replace the message text or the image being posted (see example below).

Important Notes:

  • If you simulate a mouse click within the OnUnexpectedWindow event handler, TestComplete will check for an unexpected window (that is, the event handling routine will be called recursively).

  • The OnUnexpectedWindow event does not work for windowless objects. That is, if an unexpected window is a windowless object (for example, a modal window implemented in a web application with a div element) the OnUnexpectedWindow event does not occur. For more information, see Handling Unexpected Windows.

Parameters

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.

Remarks

For information on how to create an event handler for this and other TestComplete events, see Handling Events.

Example

The following example posts the screen image to the test log and changes the text of the message that will be posted to the log:

JavaScript, JScript

function ProjectEvents1_OnUnexpectedWindow(Sender, Window, LogParams)
{
  // Posts an 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.MessageText = "My custom message";
  // You can use the following line to cancel
  // posting of the default TestComplete messages
  // LogParams.Locked = true;
}

Python

def ProjectEvents1_OnUnexpectedWindow(Sender, Window, LogParams):
  # Posts an 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.MessageText = "My custom message"
  # You can use the following line to cancel
  # posting of the default TestComplete messages
  # LogParams.Locked = True

VBScript

Sub ProjectEvents1_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.MessageText = "My custom message"
  ' You can use the following line to cancel
  ' posting of the default TestComplete messages
  ' LogParams.Locked = True
End Sub

DelphiScript

procedure ProjectEvents1_OnUnexpectedWindow(Sender; Window; LogParams);
begin
  // Posts an 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.MessageText := 'My custom message';
  // You can use the following line to cancel
  // posting of the default TestComplete messages
  // LogParams.Locked := True;
end;

C++Script, C#Script

function ProjectEvents1_OnUnexpectedWindow(Sender, Window, LogParams)
{
  // Posts an 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["MessageText"] = "My custom message";
  // You can use the following line to cancel
  // posting of the default TestComplete messages
  // LogParams["Locked"] = true;
}

See Also

Handling Unexpected Windows
Handling Events
Event Control
OnOverlappingWindow Event
Testing Modal Windows

Highlight search results