MSDN Magazine - February 2008 - (Page 115) The Microsoft UI Automation Library DR. JAMES MCCAFFREY here are several techniques you can use to test the user interface The UI test automation shown in Figure 1 is a console application of a Windows® application. For example, you can use System.Re that launches the application under test, uses the UI Automation flection classes to test Microsoft® .NET Framework applications or library to obtain references to the application and user controls on you can test both .NET and native applications by calling Win32® the app, simulates a user entering 30 and 60, and simulates click API functions such as FindWindow—either with unmanaged C++ ing on the Calculate button or with C# or Visual Basic® by using the P/Invoke mechanism. control. The test automa I believe the development In this month’s column, I will show you how to get started with tion then checks the result of the UI Automation library UI test automation using the new Microsoft UI Automation library, ing state of the application which is included in the .NET Framework 3.0 as part of Windows by examining the result is one of the most important Presentation Foundation (WPF). You can think of it as a successor TextBox control for an ex advances in test automation to the Microsoft Active Accessibility (MSAA) library, which was pected value, and it then to date. originally designed only for accessibility features but was somewhat prints a pass or fail result. coincidentally found to be useful for and adapted to UI automation. I captured the screen shot On the other hand, the UI Automation library was specifically de just before the test automation closed the application under test. signed from the beginning for both accessibility and UI test auto In the rest of this column, I will briefly describe the StatCalc mation tasks. You can use the UI Automation library to test Win32 Windows application I am testing and will explain how to launch applications, .NET Windows Forms applications, and WPF appli the application under test; how to use the UI Automation library cations on host machines running operating systems that support to get references to the application and user controls; and how to the .NET Framework 3.0 (such as Windows XP, Windows Vista®, simulate user actions and check application state. I’ll also describe Windows Server® 2003, and Windows Server 2008). how you can extend and modify the test system presented here to Let me cut to the chase and state that I believe the development meet your own needs. I think you’ll find the ability to use the new of the UI Automation library is one of the most important advances UI Automation library a great addition to your testing tool set. in test automation to date, and it will quickly become the most com monly used technique for UI test automation for Windows appli Inside StatCalc Let’s briefly look at the application under test so you’ll under cations. Compared with alternative approaches to UI automation, the UI Automation library is more powerful, often easier to use, and stand what the goal of the test automation is. You’ll also see why it more consistent. In much the same way that the .NET Framework transformed software application devel opment, I think it’s very likely that the UI Automation library will revolutionize UI test automation. A good way to show you where I’m headed is with a screenshot. Figure 1 shows a simple Windows ap plication I’m going to test. The application is called StatCalc, and it computes an arithmetic, geometric, or harmonic mean of a set of integers. An arithmetic mean is just a simple average. For example, the arith metic mean of 30 inches and 60 inches is just 45 inches. A geometric mean is used for ratios. For example, the mean of 30:1 and 60:1 is 42.4264:1. A harmonic mean is used for rates. For example, the average of 30 miles per hour and 60 miles per hour over a fixed distance is 40 miles per hour. Figure 1 Sample App under UI Test Automation february2008 115 T
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.