Addressing Objects in Visual C++ Applications

Applies to TestComplete 14.70, last modified on April 22, 2021

There are several ways to refer to objects in Visual C++ applications. If you use Name Mapping in your test project, you can refer to the application objects using their names specified in Name Mapping. For objects that are not in Name Mapping, you can use the naming syntax that directly includes identification properties and values of these objects. This topic explains both approaches.

About Object Names in the Object Browser

You can explore the object structure of the tested application in the Object Browser. Below is a sample view of a Visual C++ application's hierarchy displayed in the Object Browser:

A view of a Visual C++ application in the object tree

Click the image to enlarge it.

Here, the Process("Orders") branch of the Sys object corresponds to your tested Visual C++ application and the other objects correspond to application’s windows, controls and objects.

To refer to an individual object in the tested Visual C++ application, select the needed object in the Object Browser or Object Spy. These tools display the selected object’s name above the member list. From the right-click menu, you can copy this name to clipboard and then insert it into your test.

Copying the object name from the Object Browser

Click the image to enlarge it.

You may notice that this name differs from what you see in the object tree on the left of the Object Browser. This is because the name displayed at the top of the panel uses object aliases if they are defined, whereas the object tree uses the naming syntax that includes identification properties. The differences between the two object naming syntaxes are explained in the Addressing Visual C++ Objects Using Name Mapping and Aliases and Addressing Visual C++ Objects Without Name Mapping sections below.

You can also learn the object names in different syntaxes by looking at the following object properties:

  • MappedName - the object’s fully-qualified alias (including the aliases of all parent objects). This name is used for the object by default in your tests. Note that if the selected object is not in Name Mapping, this property is empty.

  • Name - the object name that includes the object's identification properties. This is the same name you see in the Object Browser’s object tree. For an explanation of this syntax, see below.

  • FullName - the object’s fully-qualified name in the syntax that includes the identification properties. This name consists of the object’s Name property value and the Names property value of all of the object's parent objects. See below.

Addressing Visual C++ Objects Using Name Mapping and Aliases

By default, TestComplete uses the object names from Name Mapping (the object repository) to refer to individual objects in Visual C++ applications under test. These names are called aliases. When you are recording a test, TestComplete automatically adds the recorded objects to Name Mapping and generates aliases for them.

You can see the available object aliases and add new aliases in the Name Mapping editor.

Sample Name Mapping for a Visual C++ application

Click the image to enlarge it.

Here, Mapped Objects and Aliases display the hierarchy of mapped objects and their aliases, respectively. The fully-qualified alias that can be used to refer to an object is displayed in the top right part of the Name Mapping editor (see the image above). It starts with Aliases and includes aliases of all of the object’s parent objects separated by dots (in VBScript, JScript, Python and DelphiScript projects) or square brackets (in C++Script and C#Script projects). For example, in the image above you can see that you can refer to the SysListView32 object using the following name:

JavaScript, JScript

Aliases.Orders.SysListView32

Python

Aliases.Orders.SysListView32

VBScript

Aliases.Orders.SysListView32

DelphiScript

Aliases.Orders.SysListView32

C++Script, C#Script

Aliases["Orders"]["SysListView32"]

You can copy object aliases from the Name Mapping editor to the clipboard and use them when manually adding test operations over the tested application’s objects.

The following example shows a sample item selection operation over the SysListView32 control specified by an alias:

A keyword test operation on a Visual C++ object addressed using its alias
Note: For simplicity, keyword tests do not display the Aliases identifier at the beginning of object aliases.

Also, keyword tests may not display intermediate objects in the application’s object hierarchy. To view the full name of an operation’s target object, double-click the operation or increase the Maximum depth option in the Keyword Test Editor - Groups options.

JavaScript, JScript

Aliases.Orders.SysListView32.ClickItem("Samuel Clemens", 0);

Python

Aliases.Orders.SysListView32.ClickItem("Samuel Clemens", 0);

VBScript

Call Aliases.Orders.SysListView32.ClickItem("Samuel Clemens", 0)

DelphiScript

Aliases.Orders.SysListView32.ClickItem('Samuel Clemens', 0);

C++Script, C#Script

Aliases["Orders"]["SysListView32"]["ClickItem"]("Samuel Clemens", 0);

Note that the fully-qualified mapped name for this object is the following:

JavaScript, JScript

NameMapping.Sys.Orders.wndAfx.SysListView32

Python

NameMapping.Sys.Orders.wndAfx.SysListView32

VBScript

NameMapping.Sys.Orders.wndAfx.SysListView32

DelphiScript

NameMapping.Sys.Orders.wndAfx.SysListView32

C++Script, C#Script

NameMapping["Sys"]["Orders"]["wndAfx"]["SysListView32"]

Since the wndAfx object is of no interest for our test, we exclude it from the path to the SysListView32 object in the Alias tree, so the object hierarchy becomes shorter. Using aliases lets you make your scripts shorter and more readable.

For more information about using Name Mapping and aliases, see Name Mapping and Access Objects by Aliases.

Addressing Visual C++ Objects Without Name Mapping

Your tests can work not only with applications and objects added to Name Mapping, but also with any other running applications, their windows and controls. These objects can be addressed by using a syntax that directly includes identification property values.

Consider the following sample code and keyword test that illustrate how you can refer to an object in your Visual C++ application:

A keyword test operation on a Visual C++ object that is not in Name Mapping

JavaScript, JScript

Sys.Process("Orders").Window("Afx:00400000:b*", "*").Window("SysListView32").ClickItem("Samuel Clemens", 0);

Python

Sys.Process("Orders").Window("Afx:00400000:b*", "*").Window("SysListView32").ClickItem("Samuel Clemens", 0);

VBScript

Call Sys.Process("Orders").Window("Afx:00400000:b*", "*").Window("SysListView32").ClickItem("Samuel Clemens", 0)

DelphiScript

Sys.Process('Orders').Window('Afx:00400000:b*', '*').Window('SysListView32').ClickItem('Samuel Clemens', 0);

C++Script, C#Script

Sys["Process"]("Orders")["Window"]("Afx:00400000:b*", "*")["Window"]("SysListView32")["ClickItem"]("Samuel Clemens", 0);

To learn the exact syntax for referring to a particular object, use the Object Browser - the object tree and the FullName property of objects always use this naming syntax. See the About Object Names in the Object Browser section above.

Let’s have a closer look at this notation and its components.

  • The notation starts with the Sys object that represents the operating system.

  • The next object, Process("Orders"), represents the Visual C++ application with the file name Orders.exe.

  • The other objects represent windows and controls in the Visual C++ application under test.

    Windows and controls in unmanaged Visual C++ applications do not have properties or fields whose values can be considered as object names. That is why windows and controls of Visual C++ applications are addressed by using window class names, window captions and window indexes. The Window method used for addressing Visual C++ windows and controls has the following syntax:

    Window("WndClassName", "WndCaption", WndIndex)

    The only difference is that the program objects returned by these methods will contain properties, methods and fields defined by the application code, as well as methods, properties and actions provided by TestComplete. For information on naming windows in TestComplete, see Naming Windows.

For examples of this syntax applied to objects in your tested Visual C++ application, examine your application in the Object Browser. You can also copy this syntax from the Object Browser and paste it to your test in order not to manually type it.

Combining Mapped and Unmapped Object Names

You can combine aliases specified in Name Mapping and the Window notation when referencing an object hierarchy in tests. For example, you can use aliases for parent objects and the Window notation for child objects:

VBScript

Call Aliases.Orders.Window("Afx:00400000:b*", "*").Window("SysListView32").ClickItem("Samuel Clemens", 0)

However, keep in mind that aliases must always precede the Window notation in the object hierarchy. Aliases cannot be used after the Window notation within the same statement. That is, the following statement is invalid:

VBScript

Call Sys.Process("Orders").Window("Afx:00400000:b*", "*").SysListView32.ClickItem("Samuel Clemens", 0)

Accessing Non-Visual Objects in Visual C++ Applications.

Visual C++ applications can include non-visual objects that are not displayed in the Object Browser. However, you can access these objects from your tests.

To get access to a non-visual object, you need to find a property, field or method of another object (visual or non-visual) that would return a reference to the desired object. The parent object can be either visual or non-visual, but the root object in the tree of parent objects must be a visual object. To find the needed property or method, examine the tested Visual C++ application in the Object Browser or ask the application developers where you can find it.

Currently, TestComplete does not have access to non-visual objects that cannot be obtained through methods or properties of visual objects. To be able to access a non-visual object, you need to add a method or property to certain visual object (form) of your application that will return a reference to the desired object.

See Also

Testing Visual C++ Applications
Testing Visual C++ Applications - Overview
Support for Visual C++ Applications' Controls
Accessing Native Properties and Methods of Visual C++ Objects

Highlight search results