MSDN Magazine - March 2009 - (Page 37) JAMES MCCAFFREY TEST RUN Automating UI Tests In WPF Applications In this month’s column, I show you how to write UI test automation for Windows Presentation Foundation (WPF) applications. WPF applications use a new graphics subsystem, and most traditional UI test automation techniques simply don’t work with WPF apps. Luckily, the Microsoft UI Automation (MUIA) library was designed with WPF application UI automation in mind. You can also use the Microsoft UI Automation library to test classic Win applications and WinForm-based .NET applications on host machines running operating systems that support the Microsoft .NET . Framework. Compared with older alternatives to UI automation, the Microsoft UI Automation library is more powerful and more consistent, and after an initial learning curve, you’ll find it is much easier to use. This column assumes you have some basic familiarity with WPF applications, intermediate level C# skills, but no experience Figure 1 WPF Application UI Automation with the MUIA library. resulting state of the application under test by examining the reA good way to show you where I’m headed is with a screenshot. sult text box control for an expected value and prints a pass or fail The image in Figure 1 shows that I am testing a simple but repre- result. I captured the screen shot in Figure 1 just before the test sentative WPF application. The application is called CryptoCalc, automation closed the application under test by simulating user and it computes a cryptographic hash of an input string using one clicks on the File and then Exit menu items. of three hashing techniques: MD hashing, SHA hashing, or DES In the sections of this column that follow, I will briefly describe encryption. the CryptoCalc WPF application I am testing, explain how to launch The MD (Message Digest ) hashing technique accepts an ar- the application under test, how to use the Microsoft UI Automabitrarily sized array of bytes and returns a -byte fingerprint that tion library to get references to the application and user controls, can then be used for various identification purposes. The SHA how to simulate user actions, and how to check application state. (Secure Hash Algorithm ) hashing technique is similar to MD, I’ll also describe how you can extend and modify the test system except that SHA uses a different algorithm and returns a -byte presented here to meet your own needs. I think you’ll find the abilfingerprint. The DES (Digital Encryption Standard) is a symmet- ity to use the Microsoft UI Automation library to test WPF appliric key encryption technique that can also be used to produce an cations a neat addition to your personal tool set. identifying byte array. DES crypto-hashing returns a byte array that is at least as large as the number of input bytes. The WPF Application Under Test The UI test automation shown in Figure 1 is run through a Let’s take a brief look at the WPF application under test so that console application that launches the application under test; uses you’ll understand the goal of the test automation and understand the Microsoft UI Automation library to obtain references to the application and user controls on the app; and simulates a user enSend your questions and comments for James to testrun@microsoft.com. tering “Hello!”, selecting the DES Encrypt option, and clicking on Code download available at code.msdn.microsoft.com/mag200903Test. the Compute button control. The test automation then checks the March 2009 37 http://code.msdn.microsoft.com/mag200903Test
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.