* Download Complete Source Code
In my previous post I covered doing automated user interface testing of a WPF application using Iron Ruby and Cucumber. The reason I was drawn to this path was my current interest in Ruby, Rails, and BDD. What made Bewildr such a draw for me, other than writing my tests in IronRuby, was the fact that I can use with Cucumber and have a truly human-readable natural language test.
Again, because of the learning curve and the fact that I would be introducing a completely new programming language, and let’s face it a completely new way of thinking, into a corporate environment that I will not be around to support long-term I had to pursue a more conventional solution, which led me to White.
White is an automated UI testing framework similar to Bewildr in that they both rely on the MS UI Automation Framework to hook and manipulate the user interface. What makes White a better choice given my current situation is that from a programmers perspective it is implemented and reads exactly like the standard .NET test frameworks.
Take a look at the video clip below to see what running a White test looks like.
Getting up and running with White is very easy. Other than downloading the binaries from CodePlex all you need is a tool like UISpy to help you dig deep into how the UI elements are rendered.
At the highest level White operates on the concepts of Application and Windows. Application being the application you are testing and Windows being the main surface of the application. As a best practice I would recommend spinning up the application, retrieving your window(s) and killing your application as part of test setup and teardown.
With all that in place let’s walk through setting up a couple tests.
The first thing I want to test is that when my application spins up for the first time the Log On window is displayed. Because this is an Application level test I am going to put it in a test class called ApplicationTests. I will use the practice of spinning up the app and killing it as I described above. My test will simply attempt to retrieve a window with title “Log On” and make sure it is not null.
My next test is going to be to make sure that when I enter an invalid username and password and click the log on button a message is displayed telling me my credentials are not valid. Because this test is specific to the Log On window I am going to create a new test class called LogOnTests. I will use the practice of spinning up the app, getting my window and killing the app as I described above. My test will enter an invalid username and password, click the log on button, and verify that the error message label is visible.
It’s that easy. With very little effort you can have a full suite of automated tests for testing your UI. How cool is that!?
Keith is a Senior Software Engineer with Falafel Software. He has been developing software since 1999 specializing in web-based solutions primarily using the Microsoft stack. He has been a Microsoft MVP in ASP.NET since 2012.
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in any way.