About Testing WPF Applications

Applies to TestComplete 15.68, last modified on October 01, 2024

With TestComplete, you can create and run automated tests for Windows Presentation Foundation (WPF) applications. This topic explains basic concepts of WPF application testing.

Overview of Supported WPF Technologies

TestComplete enables you to create and run automated tests for WPF applications. You can test:

See Supported WPF Technologies for details.

Creating and Recording Tests for WPF Applications

About Test Types

There are two major test formats in TestComplete:

  • Keyword tests - visually configured tests with grid-based editing interface. Best suited for novice users and those without programming knowledge.

  • Scripts - code written in one of the supported scripting languages. May be better suited for advanced users.

You select the test type when creating a test and cannot change it later. However, you can mix keyword tests and scripts within the same test project and call them from each other.

TestComplete also includes additional test types, such as low-level procedures, unit tests, and so on. You can use them to address specific testing needs. However, most automation is typically done using keyword tests and scripts.

About WPF Object Identification and Name Mapping

Each object in an application has a number of properties, such as its location, text, type and so on. Some object properties are persistent and unchanging, and therefore can be used to locate objects in applications and differentiate among various objects.

When you record a test, TestComplete captures all windows and controls that you interacted with during the recording session and adds them to the Name Mapping project item (also known as the object repository or GUI map). For each captured object, TestComplete does the following:

  • Selects a set of properties and values that uniquely identify the object in the application and saves them to Name Mapping as the object identification criteria. These properties will be used for locating the object during subsequent test recording, editing and run sessions.

  • Generates an alias (name) that will be used to reference this object in tests. By default, TestComplete generates aliases based on object names defined in the application by developers.

  • Automatically captures and adds images of the mapped objects to the Name Mapping repository. This helps you understand which window or control one or another mapped object matches.

The following image shows sample Name Mapping for a WPF application:

Sample Name Mapping for a WPF application

Here, the Customer object is identified only by one property - WPFControlName. This property specifies the object name as it is defined by the application developers in the application’s source code. However, WPF application objects can also be located by other properties, such as their class name, text and so on -- whatever best identifies a specific object. For example, TestComplete can use the WPFControlOrdinalNo and WPFControlAutomationId properties for mapping. The first property returns the control’s index among other sibling controls of the same type; the second - the value of the control’s AutomationIdProperty property as it is set in the application’s sources. It provides reliable control recognition provided that developers set the property value in the source code.

If needed, you can modify the default Name Mapping generated by TestComplete. For example, you can:

For more information, see Name Mapping.

Keep in mind that the object hierarchy in Name Mapping mirrors the object hierarchy in the tested application. When locating an object, TestComplete takes into account its entire parent hierarchy. If any object in the parent hierarchy cannot be found using the specified property values, the target object cannot be located as well. That is why it is important to select unique and unchanging properties for object identification.

About Support for WPF Controls

TestComplete provides out-of-the-box support for many standard and third-party WPF GUI controls. It has many built-in operations for automating various user actions against these controls, such as item selection, grid cell clicks, tree node expanding, data retrieval and so on. When you record a test, TestComplete records the performed GUI actions using these special operations.

To learn which operations are available for a specific WPF control in your tested application, you can examine this object in the Object Browser or Object Spy.

See Support for WPF Applications' Controls for more information.

Note: If your WPF application contains a control that represents a collection of items (for example, a combo box or a list box), and the control uses data binding for its items, TestComplete may fail to access those items correctly. To get the items, you can use the control’s native properties.

Using Native WPF Methods and Properties in Testing

For the most flexible and powerful automation possible, TestComplete not only provides built-in test objects, methods and properties, but also exposes all native and attached properties and methods of objects in WPF applications. These are the same properties and methods that are available in the application’s source code and are used by the application developers. You can use these native properties and methods to automate custom operations that are not available out-of-the-box.

Note: Note that, some native properties and methods of WPF objects are unavailable to TestComplete. For more information, see Object Properties, Fields and Methods That Are Unavailable to TestComplete.

For detailed information on how to address exposed properties and methods from your tests, see Accessing Native Properties and Methods of WPF Objects and Addressing Objects in WPF Applications.

Viewing Object Properties and Methods

To see what operations (methods) are available for objects in your tested WPF application, as well as the object properties and their values, you can use the Object Browser or Object Spy. Available properties and methods include those provided by TestComplete, as well as native object properties and methods defined by the developers in the application’s source code.

You can view object properties and methods both at design time and at run time when the test is paused.

For more information on using the Object Browser, see Object Browser and Exploring Applications.

Viewing Attached Properties

In TestComplete, you can access attached properties of WPF objects. Use the following syntax for the attached properties:

Attached-Property-Provider_Property-Name

For example, Grid_Row.

Important Notes

  • In the Object Browser, Object Spy and Code Completion panels, you can view attached properties only with non-default values (those that were explicitly defined in the application's source code). You can access attached properties with default values from tests, but the Object Browser, Object Spy and Code Completion panels will not show these properties.

  • Using several attached properties with identical names (even with different namespaces and assemblies) is not supported.

Samples

TestComplete includes a number of sample WPF applications and test projects for them. You can examine these samples to better understand how to implement some common automated testing scenarios.

Sample Location Description
<TestComplete Samples>\Desktop\Orders\WPF General-purpose testing sample for a sample C# WPF application, Orders.
<TestComplete Samples>\Desktop\Orders\WPF3D Example of testing a C# WPF application that uses customized controls and visualizations.

For information about sample applications and test projects included in TestComplete, see TestComplete Samples.

Where to Go Next

For further information about automating tests with TestComplete, refer to the following sections:

See Also

Testing WPF Applications
Supported WPF Technologies
Requirements for Testing WPF Applications
Addressing Objects in WPF Applications
Support for WPF Applications' Controls

Highlight search results