Introduction to Microsoft UIAutomation and Practical Usage for UI Testing
This article introduces Microsoft UIAutomation, explains its architecture and AutomationElement model, compares UI element inspection tools (UISpy vs Inspect), demonstrates how to capture element properties with Inspect, and shows how to write C# automation scripts while highlighting common testing challenges.
In the field of UI automation testing, many popular tools such as Selenium, Katalon, UFT (formerly QTP), and IBM's Rational Functional Tester are widely known, but this article focuses on the lesser‑known yet practical Microsoft UIAutomation library.
UIAutomation is a .NET Framework component that enables interface automation for C/S applications, designed originally for accessibility and UI testing tasks, and works on Windows operating systems (XP, Vista, 7, Server 2003/2008) to automate Win32, .NET Windows Forms, and WPF applications.
All windows and controls are represented as AutomationElement objects, each containing properties of the UI element; the entire desktop UI forms an UIAutomation tree with a root node representing the desktop, from which elements can be located via Process ID, Process Name, or Window Name and accessed through patterns.
The UIAutomation architecture consists of server‑side DLLs (UIAutomationProvider.dll, UIAutomationTypes.dll), client‑side DLLs (UIAutomationClient.dll, UIAutomationCore.dll), and supporting libraries such as UIAutomationClientSideProvides.dll that facilitate interaction between client and server.
For practical UIAutomation work, two inspection tools are available: UISpy and Inspect. Based on testing experience, Inspect is recommended because it reliably discovers UI elements, whereas UISpy may miss some controls.
Inspect is a lightweight (<1 MB) tool that runs without installation; its interface shows a tree view of UI elements on the left (rooted at “Desktop Pane”) and displays selected element properties (Name, AutomationId, ControlType, etc.) on the right, along with navigation buttons to traverse the UIAutomation tree.
During testing, moving the cursor over a UI element updates the property pane, allowing testers to capture attributes such as ClassName, AutomationId/Name, Ancestors, and ControlType; these properties are recorded in an Excel file for later use.
After gathering element information, automation scripts can be written in C# (or other languages) to drive the UI objects, as illustrated in the provided example screenshot.
The article notes that while UIAutomation offers flexibility and a quick learning curve for experienced programmers, it still suffers from common UI testing pain points like high entry barriers, costly asset accumulation, environment and personnel turnover, and expensive maintenance when UI elements change.
To address these issues, the Agricultural Bank of China R&D Center has defined a natural‑language‑based test description language called “商语言” that enables business‑oriented testers to write maintainable test cases that are automatically converted into QTP/UIAutomation/Selenium scripts; further details will be presented in a future article.
DevOps
Share premium content and events on trends, applications, and practices in development efficiency, AI and related technologies. The IDCF International DevOps Coach Federation trains end‑to‑end development‑efficiency talent, linking high‑performance organizations and individuals to achieve excellence.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.