Simulating User Actions on Application Windows

Applies to TestComplete 15.46, last modified on January 09, 2023

To simulate user actions over windows of desktop applications and of web browsers, use methods that TestComplete provides for all Window and BrowserWindow 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 (TestComplete treats controls in desktop applications as windows as well).

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.

The image below shows a keyword test that simulates basic actions on a window — restores it, minimizes it, and so on.

Simulating actions on the Notepad window from a keyword test
Simulating actions on a browser window

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

In script tests

To simulate user actions over desktop application windows and browser windows in scripts, you can use methods and properties of the Window and BrowserWindow objects respectively. The following example shows how to simulate basic user actions over a window:

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"]();

JavaScript, JScript

var w = Sys.Browser().BrowserWindow(0);
w.Activate();
w.Minimize();
w.Restore();
w.Position(10, 10, 450, 250);
w.Maximize();
w.Restore();
w.SetFocus();

Python

w = Sys.Browser().BrowserWindow(0)
w.Activate()
w.Minimize()
w.Restore()
w.Position(10, 10, 450, 250)
w.Maximize()
w.Restore()
w.SetFocus()

VBScript

Set w = Sys.Browser().BrowserWindow(0)
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.Browser().BrowserWindow();
  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["Browser"]()["BrowserWindow"](0);
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