Yoiu can look into existing Windows Automation API : UI Automation, MSDN documentation
Run-Time Requirements
UI Automation is supported on the following operating systems: Windows XP, Windows Server 2003, Windows Server 2003 R2, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2.
Client applications, from simple test scripts to robust record and playback utilities, may require access to elements that are not currently instantiated, such as a file open dialog or a menu item and therefore do not exist in the UI Automation tree. These elements can only be instantiated by reproducing, or "playing back", a specific sequence of user interface (UI) actions through the use of UI Automation properties such as AutomationID, control patterns and event listeners. See Test Script Generator Sample for an example that uses Microsoft UI Automation to generate test scripts based on user interaction with the user interface (UI).
You can use AutomationIdProperty inside existing Visual Studio project.
Implementing UI Automation in a Test Application
- Add the UI Automation References.
The UI Automation dll's necessary for UI Automation clients are listed here.
UIAutomationClient.dll provides access to the UI Automation client-side APIs.
UIAutomationClientSideProvider.dll provides the ability to automate Win32 controls. See UI Automation Support for Standard Controls.
UIAutomationTypes.dll provides access to the specific types defined in UI Automation.
- Add the System.Windows.Automation namespace.
This namespace contains everything UI Automation clients need to use the capabilities of UI Automation except text handling.
- Add the System.Windows.Automation.Text namespace.
This namespace contains everything a UI Automation clients need to use the capabilities of UI Automation text handling.
- Find controls of interest
Automated test scripts locate UI Automation elements that represent controls of interest within the automation tree.
There are multiple ways to obtain UI Automation elements with code.
Query the UI using a Condition statement. This is typically where the language-neutral AutomationIdProperty is used.
Note
An AutomationIdProperty can be obtained using a tool such as UISpy.exe (UI Spy) that is able to itemize the UI Automation properties of a control.
Use the TreeWalker class to traverse the entire UI Automation tree or a subset thereof.
Track focus.
Use the hWnd of the control.
Use screen location, such as the location of the mouse cursor.
See Obtaining UI Automation Elements
Control patterns expose common behaviors for functionally similar controls.
After locating the controls that require testing, automated test scripts obtain the control patterns of interest from those UI Automation elements. For example, the InvokePattern control pattern for typical button functionality or the WindowPattern control pattern for window functionality.
See UI Automation Control Patterns Overview.
Automated test scripts can now control any UI of interest from a UI framework using the information and functionality exposed by the UI Automation control patterns.
Related Tools and Technologies
There are a number of related tools and technologies that support automated testing with UI Automation.
UISpy.exe (UI Spy) is a graphical user interface (GUI) application that can be used to gather UI Automation information for both provider and client development and debugging. UI Spy is included in the Windows Software Development Kit (SDK).
UIAutoCmd is a command-line tool with capabilities similar to UI Spy.
MSAABridge exposes UI Automation information to Active Accessibility clients. The primary goal of bridging UI Automation to Active Accessibility is to allow existing Active Accessibility clients the ability to interact with any framework that has implemented UI Automation.
Security
For security information, see UI Automation Security Overview.