UIA Pro best practices

This topic describes best practices and guidelines for using the UIA Pro add-in to interact with UI elements.

Selecting the best method for your step

In UIA Pro, multiple methods can often achieve the same outcome. However, the availability and effectiveness of each method depends on the application you're testing and the specific UI Automation patterns it supports. Selecting the appropriate method requires understanding the UI structure and the capabilities exposed by the target application. Not all methods are always supported.

Consider the following guidelines when deciding which methods to use:

  • Validate pattern availability.

    When a control supports multiple patterns, select the one that aligns most closely with the action you need to simulate, preferring UIA specific methods. To check supported patterns during runtime, use HasSupportedPattern or HasSupportedPatterns methods. Make sure your test can handle scenarios where patterns might not be available during runtime.

  • Start with high-level functions for common tasks and progress to low-level functions in complex scenarios.

  • Verify an object's functionality.

    A control type's visual appearance may resemble a standard UI element (such as Button or dropdown), but its behavior might be different. For example, a control that looks like a button might not support the InvokePattern. Instead, it could implement a different pattern such as TogglePattern or even custom behavior.

    Always inspect the control type's supported patterns programmatically rather than relying on its appearance.

  • Prefer UIA-Specific Methods.

    For greater reliability and flexibility, especially when working with complex user interfaces, use pattern-based methods rather than device replay methods if possible.

    Example: Button click

    We recommend using the UIA pattern based Invoke method instead of the device replay Click method, when possible.

    For example, prefer using the invoke method from InvokePattern.Invoke instead of the Click method from test object for the following reasons:

    UIA pattern method (Invoke) Device replay method (Click)
    Uses UIA framework calls directly Simulates a physical mouse click
    Can work even when UI elements are not directly visible Subject to UI responsiveness issues
    Not dependent on UI responsiveness None
    More reliable if the pattern is supported None
  • Consider how the application implements UIA patterns.

    When deciding which high-level method to use, consider the low-level methods it is based on, and how the application implements them.

    Example: Retrieving a cell value from a table

    While table cells in an application may appear visually similar, they expose data differently through ValuePattern, TextPattern, or both.

    To retrieve a table cell's value, you can use the high-level methods GetCellValue or GetCellText:

    • GridPattern.GetCellValue(0,0)

    • GridPattern.GetCellText(0,0)

    Select which method to use, depending on how the application implemented ValuePattern, TextPattern.

    GetCellText retrieves the cell's content by calling TextPattern.GetText, and GetCellValue calls ValuePattern.GetValue.

Back to top

Using the path description property

You must use a path property in your test object description when your test object hierarchy omits intermediate objects that exist in the UI object hierarchy.

When a path property is not specified, the path is a concatenation of the parent test object's path (if a parent exists) and a path segment that corresponds to the current test object's control type.

Example: A path property would be required in the following case:

The UI Hierarchy includes the following objects: Window → Pane → Pane → List → ListItem.

Your test describes the Pane and ListItem objects:

  • Parent path: Window;Pane;Pane

  • Child path: Window;Pane;Pane;List;ListItem (or ~List;ListItem, if you are using relative paths.)

Both objects require a path property to be specified because not all UI objects are represented by test objects.

Note: The decision about which objects to represent and which to omit from the hierarchy takes into account the performance, maintainability, and reliability of the object identification. We recommend maintaining the hierarchy created when the objects are learned. You can change path properties from absolute paths to relative ones to simplify test maintenance. For details, see Relative paths in object descriptions.

Back to top

See also: