Microsoft UIAutomation library

Thanks to my colleague Suyog gupta, I learnt of this UI automation support available in  .Net 3.0 available through the new UIAutomationClient assembly. This consists of classes that can be used to test UI interactions and UI sequence flows helping us to build automated User interface testing tools for our applications.

When Suyog was building the test automation client, i was trying to understand the concepts behind. This is what I found. Hope this automation framework will help the test developers learn the concept of automation testing more than  capability of automated tools(they are good, but are costly!). I found the help available on this topic to be limited on googling. We are using this for testing Windows Forms application, but i see that it can be used to test WPF applications too.

This concept seems toe have a provider client model. Provider API (UIAutomation.dll and UIAutomationTypes.dll) consists of interfaces that need to be implemented by UI Automation providers, objects that provide information about UI elements and respond to programmatic input. One can consider the application product that is to be tested to support provider API.Client API (UIAutomationClient.dll and UIAutomationTypes.dll) is a set of types for managed code that enables UI Automation client applications to obtain information about the UI and to send input to controls. One can consider the UIAutomation test client to support the Client API.

.Net provides the underlying code that handles communication between providers and clients. The UI Automation framework also provides information to clients through events.  UI Automation clients subscribe for specific events on a specific scope and UI Automation providers can improve performance by raising events only if there are clients subscribed to them.

Key element of this Object model is AutomationElement. An AutomationElement is not a control, but an object that represents the accessible properties of a control and it will be able to provide just as much information and interaction as the control’s provider can give. All automation elements are part of a tree, in which the root element is the desktop.

There are multiple ways to obtain UI Automation elements within a client application’s code:

  • using a query with a Condition statement to find a control,
  • using the TreeWalker class to traverse the entire UI Automation tree or a subset of it,
  • use the hWnd of the control, its screen location, etc.

You can make use of the tool UISpy to view and understand application’s UI hierarchical structure, property values, and raised events. UISpy provides two methods  to select a UI item and know more about the same: focus tracking and hover mode. The first one tracks the UI item that has the keyboard focus and the second is more helpful to select a specific UI item

To understand better , one can look at the article written by Soledad Pano