UIA Pro Add-in Best practices
Relevant for: GUI tests and components
This topic describes best practices and guidelines for using the UIA Pro Add-in to interact with UI elements.
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.
For details, see UIA Pro functions.
-
Verify an object’s functionality
A control type’s visual appearance may resemble a standard UI element (e.g. 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
UIAProButton("Button").InvokePattern.Invoke
instead ofUIAProButton("Button").Click
for the following reasons:UIA pattern method (Invoke)
Device replay method (Click)
Uses UIA framework calls directly
Simulates a physical mouse click
Not dependent on UI responsiveness Subject to UI responsiveness issues Can work even when UI elements aren't directly visible 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's 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:
-
UIAProDataGrid("Grid").GridPattern.GetCellValue(0,0)
-
UIAProDataGrid("Grid").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.
-
See also: