Choosing Between Microsoft UI Automation Library and Coded UI Test for WPF Application Testing

Choosing Between Microsoft UI Automation Library and Coded UI Test for WPF Application Testing

11 April 2024 Stephan Petzl Leave a comment Tech-Help

When it comes to automating UI testing for applications, particularly for WPF applications, testers commonly face the dilemma of choosing between the Microsoft UI Automation Library and Coded UI Test. This article aims to provide guidance on selecting the appropriate tool based on the scenario and requirements of your project.

Understanding Microsoft UI Automation Library

The Microsoft UI Automation (UIA) is a robust accessibility framework introduced with .Net 4.0. It is inherently supported by WPF applications through the AutomationPeer class, which helps in making UI elements accessible to automation tools.

UIA is typically a lower-level library, which means it can require more effort and coding expertise to write tests directly against it. This can be a powerful approach but is often more time-consuming and complex.

Exploring Coded UI Test

Coded UI Test is a feature included in Visual Studio 2010 and later, designed to facilitate UI testing by providing a record and playback tool. It is built on top of the Microsoft UI Automation Library and helps to improve quality assurance productivity by enabling the recording of test cases instead of coding them from scratch.

For applications that have been designed with automation in mind, Coded UI Test can be quite sufficient. If your application lacks AutomationIDs, it is essential to ensure that controls have some unique property, like a Name, to identify them. Tools like UIVerify or Inspect can be used to check for this.

Techniques for Handling Missing AutomationIDs

If your application does not have unique properties for certain controls, you may need to employ additional techniques to automate your tests:

  • From an Event: Use an AutomationElement as the source object in your event handler, such as for focus-changed events.
  • From a Point: Retrieve an AutomationElement using the static FromPoint method with screen coordinates, such as a cursor position.
  • From a Window Handle: Use the static FromHandle method to get an AutomationElement from an HWND.
  • From the Focused Control: Use the static FocusedElement property to obtain an AutomationElement representing the focused control.

Deciding on the Right Tool for Your Project

Choosing between Microsoft UI Automation Library and Coded UI Test depends on your specific needs:

  • If you are looking for a tool that allows for quick test recording and is sufficient for applications with planned automation support, Coded UI Test is a good option.
  • If your application requires a more detailed and lower-level control for automation, or if you have the expertise and need for a custom solution, consider using the Microsoft UI Automation Library directly.

It’s also worth noting that while Coded UI Test can be easier to start with, it might not scale well for larger test suites. In such cases, looking into other high-level libraries like TestStack’s White may be beneficial.

Conclusion

Both the Microsoft UI Automation Library and Coded UI Test offer powerful capabilities for automating UI testing in WPF applications. Your choice should be guided by the complexity of your application, the scale of your testing needs, and your team’s expertise. Consider the unique properties of your UI elements, the potential need for lower-level control, and the productivity gains from recording tests when making your decision.

Like this article? there’s more where that came from!