Handling unexpected windows that affect TestComplete

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.

Getting ready

Launch the standard Windows Notepad (C:Windows otepad.exe) application.

How to do it...

To create the Print window handler, it is necessary to perform the following steps:

  1. First of all, let's create a script which will execute some actions (for example, type a text) in the Notepad:
    function testUnexpectedWindowHandling1()
    {
      var np = Sys.Process("NOTEPAD").Window("Notepad");
      np.Activate();
      for(var i = 1; i < 1000; i++)
      {
        np.Keys(i + "[Enter]");
      }
    }
  2. Create the OnUnexpectedWindow event handler.
  3. In the created event handler write the following code:
    if(Window.WndCaption == "Print")
    {
      Log.Message("Print window appeared, waiting...");
      while(Window.Exists)
      {
        aqUtils.Delay(500, "Print window appeared, waiting...");
      }
    }
  4. Launch the testUnexpectedWindowHandling1 function. As the function is working, press the following Ctrl + P keys combination, wait a little, and close the Print window.
  5. Repeat the action several times. You will notice that script execution will be paused each time as the Print window shows up, and resumed after the Print window is closed.

How it works...

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.

See also

  • The process of the event handler creation is thoroughly dealt with in the Creating event handlers recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.71.21