Working With Owner-Drawn ToolBars

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

In order for TestComplete to work with individual toolbar buttons in scripts or keyword tests, it needs a way to identify and specify them. For this purpose, TestComplete uses either item captions, indexes (position within the toolbar) or IDs. Captions are more usually preferable than indexes, because they make tests more readable and stable, whereas indexes are less easy to understand and, moreover, they may change during the run. IDs also provide a stable way to identify toolbar buttons, but they are less easy to understand than indexes.

Standard Win32 controls are drawn by the operation system itself. However, Windows also lets applications handle drawing their controls, including toolbars, in a custom way. The controls drawn by the application are called owner-drawn. In general, owner-drawn controls may have no labels and their contents can be arbitrary. To learn whether your tested application owner draws its controls, ask the tested application developers.

If the toolbar is owner-drawn, TestComplete identifies its buttons using IDs. This means that TestComplete records actions with owner-drawn toolbars using button IDs. Since button IDs are constant, their usage ensures the scripts and keyword tests stability. When writing scripts for testing owner-drawn toolbars manually, you should also specify buttons by IDs (see Addressing Toolbar Buttons). For example:

w.Window("MyCustomToolbarClass", "*").ClickItem(3802)

Tip: To make the test more readable, you can create special constants that will hold the button IDs and use these constants rather than the corresponding numeric values in the property and method calls:

JavaScript, JScript

var btnNew = 3802;
...
w.Window("MyCustomToolbarClass", "*").ClickItem(btnNew);

Python

btnNew = 3802
...
w.Window("MyCustomToolbarClass", "*").ClickItem(btnNew)

VBScript

Const btnNew = 3802
...
w.Window("MyCustomToolbarClass", "*").ClickItem(btnNew)

DelphiScript

const btnNew = 3802;
...
begin
  ...
  w.Window('MyCustomToolbarClass', '*').ClickItem(btnNew);
  ...
end;

C++Script, C#Script

var btnNew = 3802;
...
w["Window"]("MyCustomToolbarClass", "*")["ClickItem"](btnNew);

This approach also makes it easier to update the test if button IDs in the tested application change in the next application version.

To specify items of owner-drawn toolbars by text, try using the appropriate approaches described in the Object Identification section. For other tips on dealing with non-standard controls, see Ways to Interact With Application Objects.

See Also

Working With Toolbars
Testing Owner-Drawn Controls
Working With Third-Party Toolbars
Addressing Toolbar Buttons

Highlight search results