Simulating User Actions on Application Windows

Applies to TestComplete 15.10, last modified on December 15, 2021

To simulate user actions on application windows (maximization, minimization and so on), use special actions that TestComplete provides for all 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.

In Keyword Tests

You can simulate user actions over application windows by using the appropriate methods of the window object. To call the methods, you can use the On-Screen Action or Call Object Method operations. For example:

  1. Open your keyword test for editing.

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

  3. Drag the target glyph to the needed window or control or click to point to the needed window or control with the mouse.

    Note: To simulate user actions on a top-level window, drag the target glyph strictly to the caption of that window.

    The wizard will show the selected window or control. Click Next.

  4. The second page of the wizard will display the list of available methods of the object. Choose the needed action from the list and click Next to continue.

  5. On the third page of the Operation Parameters wizard, you can specify the method’s parameters (if any).

  6. Click Finish to complete the operation creation and close the wizard.

  7. If needed, repeat all described steps to add more actions on your window to your test.

For example, the image below shows a keyword test that simulates various actions on the Notepad window - restores it, minimizes it, and so on:

Simulating actions on the Notepad window from a keyword test

For more information on how to perform typical tasks in keyword tests, see Common Tasks for Keyword Test Operations.

From Scripts

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

The following example simulates various actions over the Notepad window - minimizes it, restores it, and so on:

JavaScript, JScript

var w = Sys.Process("notepad").Window("Notepad", "*", 1);
w.Activate();
w.Minimize();
w.Restore();
w.Position(10, 10, 450, 250);
w.Maximize();
w.Restore();
w.SetFocus();

Python

w = Sys.Process("notepad").Window("Notepad", "*", 1)
w.Activate()
w.Minimize()
w.Restore()
w.Position(10, 10, 450, 250)
w.Maximize()
w.Restore()
w.SetFocus()

VBScript

Set w = Sys.Process("notepad").Window("Notepad", "*", 1)
w.Minimize
w.Restore
w.Activate
w.Minimize
w.Restore
Call w.Position(10, 10, 450, 250)
w.Maximize
w.Restore
w.SetFocus

DelphiScript

var w;
begin
  w := Sys.Process('notepad').Window('Notepad', '*', 1);
  w.Activate;
  w.Minimize;
  w.Restore;
  w.Position(10, 10, 450, 250);
  w.Maximize;
  w.Restore;
  w.SetFocus;

end;

C++Script, C#Script

var w = Sys["Process"]("notepad")["Window"]("Notepad","*", 1);
w["Activate"]();
w["Minimize"]();
w["Restore"]();
w["Position"](10, 10, 450, 250);
w["Maximize"]();
w["Restore"]();
w["SetFocus"]();

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