Simulating User Actions on Application Windows

Applies to TestComplete 12.60, last modified on September 17, 2018

To simulate user actions on application windows (maximization, minimization and so on), use the special actions provided by TestComplete window objects:

  • Activate - Activates the top-level window.
  • Maximize - Maximizes the top-level window.
  • Minimize - Minimizes the top-level window.
  • Position - Sets the position and size of the top-level window.
  • Restore - Restores the minimized top-level window.
  • SetFocus - Moves the input focus to a top-level window or to a control (since controls are windows).

You can use these methods in keyword tests and scripts. The following sections provide detailed information on how to simulate user actions over applications from your tests.

Simulating in Keyword Tests

You can simulate user actions over application windows by using the appropriate methods of the window object. For instance, you can add the On-Screen Action or Call Object Method operation to a keyword test, select the needed method and specify its parameters. For instance, to minimize and restore the Notepad window, add the On-Screen Action operation and specify its parameters according to the following steps:

  • Open your keyword test for editing.

  • Add the On-Screen Action operation to the test. After the operation is dragged, TestComplete will display the Operation Parameters wizard.

  • Drag the target glyph () to the desired window or control, which should be affected. For instance, if we drag the glyph to the Notepad window caption and then release the mouse button, the following object will be added in the Operation Parameters dialog: “Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1)”. Note that to get access to the methods, which simulate actions on a top-level window, you should drag the target glyph strictly to the caption of this window. Otherwise, these methods will not be shown in the list of available methods in the second page of the wizard. Click Next.

  • The second page of the wizard will display the list of available methods of the object. Choose the proper action from the list and click Next to continue. In our case, to minimize the Notepad window one should select the Minimize method.

  • On the third page of the Operation Parameters wizard you can specify the method’s parameters. In our case, the Minimize method does not use parameters.

  • Click Finish to save changes and to close the wizard.

  • Repeat all described steps and add another On-Screen Action to the test. Specify the same Notepad window and choose the Restore method in the wizard. It also does not use parameters.

Now after running your keyword test the Notepad window will be minimized and then restored. For more information on how to perform typical tasks in keyword tests, see Common Tasks for Keyword Test Operations.

Simulating From Script

You can also use the actions described above to perform various operations on application windows from your scripts.

The following example minimizes and then restores the Notepad window:

JavaScript, JScript

var w = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1);
w.Minimize();
w.Restore();

Python

w = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1)
w.Minimize()
w.Restore()

VBScript

Set w = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1)
w.Minimize
w.Restore

DelphiScript

var w;
begin
  w := Sys.Process('notepad').Window('Notepad', 'Untitled - Notepad', 1);
  w.Minimize;
  w.Restore;
end;

C++Script, C#Script

var w = Sys["Process"]("notepad")["Window"]("Notepad","Untitled - Notepad", 1);
w["Minimize"]();
w["Restore"]();

The following example minimizes and then restores the currently active window:

JavaScript, JScript

var w = Sys.Desktop.ActiveWindow();
w.Minimize();
w.Restore();

Python

w = Sys.Desktop.ActiveWindow();
w.Minimize()
w.Restore()

VBScript

Set w = Sys.Desktop.ActiveWindow
w.Minimize
w.Restore

DelphiScript

var w;
begin
  w := Sys.Desktop.ActiveWindow;
  w.Minimize;
  w.Restore;
end;

C++Script, C#Script

var w = Sys["Desktop"]["ActiveWindow"]();
w["Minimize"]();
w["Restore"]();

See Also

Simulating User Actions

Highlight search results