Simulating Menu Actions

Applies to TestComplete 15.70, last modified on December 17, 2024

About

An object may have several types of menus associated with it: top-level windows may have the main menu, the system menu and the context menu, child windows and controls may also have a context menu. To work with menus in tests, use the Menu object. This object provides a number of methods and properties that let you perform various menu operations:

Method or Property Description
Click Simulates a click on a menu item.
Check Simulates checking or unchecking of a menu item.
Select Simulates placing the mouse pointer over a menu item.
Items Provides access to individual menu items.
Count Returns the number of items in a menu.

Menus are not available in the application’s object hierarchy directly, and you cannot view them in the Object Browser.

To access menus in tests, use the following properties:

While windows’ main and system menus are always accessible to the test engine, context menus must be displayed on screen first since TestComplete cannot invoke context menus automatically. To invoke a context menu, add a test operation that right-clicks the appropriate window or control or sends the Application key press to it.

The easiest way to add menu actions to your test is to record them. However, you can also add the appropriate test operations at design time. The remainder of this topic explains how you can do this. For more information about working with menus in tested applications, see Working With Menus in Desktop Windows Applications.

Simulating menu actions in keyword tests

In keyword tests, you can simulate various menu operations using the Menu Action operation. Below are step-by-step instructions on adding and configuring this operation:

  1. Open your keyword test in the Keyword Test editor.

  2. If you are going to simulate a context menu action, you first need to add and configure the On-Screen Action operation that invokes that menu, otherwise the menu will not be available:

    1. Add the On-Screen Action operation to your test. TestComplete will display the Operation Properties wizard.

    2. Drag and drop the target glyph () to the window or control whose context menu you want to work with and press Next.

    3. In the list of available methods, select ClickR and press Next.

    4. Specify the coordinates of the point within the window or control where TestComplete should right-click and press Finish.

  3. Add the Menu Action operation to the test. TestComplete will display the Operation Parameters wizard.

  4. Choose the type of the menu you are going to work with: main, system or context and click Next.

  5. Drag and drop the target glyph () to the window or control whose menu you want to work with and click Next. Note, that to pick a window you need to drop the target glyph to the window’s caption rather than the client area, because the latter may contain child controls.

  6. In the list of available menu actions, choose the one you need and click Next.

  7. Finally, specify the parameter values for the selected method. Most menu actions have a parameter that holds the “path” to the menu item, for example, File|New. See Addressing Menu Items in Desktop Windows Applications.

  8. Click Finish to save changes and to close the wizard. TestComplete will append the configured Menu Action operation to your test.

You can also simulate menu actions using the Call Object Method operation. For more information on how to perform daily tasks in keyword tests, see Common Tasks for Keyword Test Operations.

Simulating menu actions in scripts

To simulate menu actions in a script test, get the Menu object corresponding to the target menu and then call the object’s methods. The following code sample shows how to call the Minimize command of the system menu (provided that the appropriate parent window is running):

JavaScript, JScript

var w = Sys.Process("Notepad").Window("Notepad", "*");
w.SystemMenu.Click("Minimize");

Python

p = Sys.Process("notepad")
w = p.Window("Notepad", "*")
w.MainMenu.Click("File|New")

VBScript

Set w = Sys.Process("Notepad").Window("Notepad", "*")
w.SystemMenu.Click("Minimize")

DelphiScript

var w;

begin

  w := Sys.Process('Notepad').Window('Notepad', '*');
w.SystemMenu.Click('Minimize');

end;

C++Script, C#Script

var w = Sys["Process"]("Notepad")["Window"]("Notepad", "*");
w["SystemMenu"]["Click"]("Minimize");

JavaScript, JScript

var w = Sys.Browser().BrowserWindow(0);
w.SystemMenu.Click("Minimize");

Python

w = Sys.Browser().BrowserWindow(0)
w.SystemMenu.Click("Minimize")

VBScript

Set w = Sys.Browser().BrowserWindow(0)
w.SystemMenu.Click("Minimize")

DelphiScript

var w;

begin

  w := Sys.Browser().BrowserWindow(0);
  w.SystemMenu.Click('Minimize');

end;

C++Script, C#Script

var w = Sys["Browser"]()["BrowserWindow"](0);
w["SystemMenu"]["Click"]("Minimize");

For more script samples and detailed information about performing various operations with menus, see Working With Menus in Desktop Windows Applications.

Using Low-Level and Native Menu Actions

If the application you are testing uses a third-party menu component that is not recognized by TestComplete, you can still work with this menu as a “black-box” onscreen object. For example, you can select items using the Click action or by simulating the items’ access keys. See Simulating Mouse Actions and Simulating Keystrokes.

If the tested application is an Open one, you can also use “native” methods and properties of the menu component to perform the desired actions. To find the method or property that can be used to perform the desired menu action, explore the menu component in the Object Browser, refer to the component’s documentation or ask the tested application’s developers. See Working With Third-Party Menus in Desktop Windows Applications for more information.

See Also

Simulating User Actions
Working With Menus in Desktop Windows Applications
Addressing Menu Items in Desktop Windows Applications
Working With Third-Party Menus in Desktop Windows Applications

Highlight search results