An unexpected window is a window which shows up as scripts are being executed, affecting TestComplete interaction with tested application. In the project settings, it is possible to specify what should be done with such windows (whether they should be ignored, paused, or stopped; or a number of simple actions could occur); however, in some cases, it is convenient to handle some of the windows (known to us) independently.
In this recipe, we will consider an example of working with the Print window of the Notepad application. To simulate unexpected appearance of the window, we would be evoking it ourselves, pressing the Ctrl + P keys combination. Our script would input the text into Notepad and, upon the Print window appearing, enter a corresponding message to the log about the event; and then simply wait for the window to close out. Closing the window is also expected to be done manually.
To create the Print window handler, it is necessary to perform the following steps:
function testUnexpectedWindowHandling1() { var np = Sys.Process("NOTEPAD").Window("Notepad"); np.Activate(); for(var i = 1; i < 1000; i++) { np.Keys(i + "[Enter]"); } }
OnUnexpectedWindow
event handler.if(Window.WndCaption == "Print") { Log.Message("Print window appeared, waiting..."); while(Window.Exists) { aqUtils.Delay(500, "Print window appeared, waiting..."); } }
testUnexpectedWindowHandling1
function. As the function is working, press the following Ctrl + P keys combination, wait a little, and close the Print window.The OnUnexpectedWindow
event handler has the Window
parameter, which is the targeted unexpected window, hindering work with TestComplete. This window could be handled as any other of its kind (refer to its properties and evoke its methods).
Via the aqUtils.Delay
method, we are pausing the execution; otherwise, the TestComplete process will perform many checks in-between small intervals, which could slow down other running programs.
18.219.71.21