Introduction
The White UI automation library is an interesting approach for testing Win 32, WPF (Windows Presentation Foundation) and Silverlight GUI applications on the Windows platform. This blog post explains how a GUI automation test engineer can get started with it.
What you need
Authoring UI automation tests with White requires the following tools:
Visual Studio 2010
The Express editions are free and can be downloaded here: http://www.microsoft.com/express/
UISpy
This is a tool that lets you analyze UIs that are based on WinForms and WPF. This tool shipped with a particular version of the Windows SDK. This version can be downloaded here: http://www.microsoft.com/downloads/en/details.aspx?familyid=4377F86D-C913-4B5C-B87E-EF72E5B4E065&displaylang=en. You don’t need to install everything. Use the web installer. Just select the Windows Development Tools and un-select the rest. By default the tool will be installed in the following path: C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin.

Figure 1: To speed up the install and save some space on your hard drive, just select the Windows Development Tools option.
White
The White open source project is hosted on CodePlex. Download the latest release and un-zip it. Here is the project and download link: http://white.codeplex.com/
Setting up Visual Studio with White
Start Visual Studio and select New Project. The default .NET Framework 4.0 option will not work without some tweaks. Select .NET Framework 3.5 from the drop down box and click on the Console Application list item underneath.

Figure 2: Start->New Project: Select .NET Framework 3.5 and Console Application (C#)
Click OK and the Visual Studio IDE opens the new project.

Figure 3: The new project in the IDE
Next click Ctrl-Shift-B to build the project.
Create a new folder called White in the bin folder of your Visual Studio project and copy the un-zipped White files into that folder.

Figure 4: Copy the White files into the bin\White folder of your Visual Studio project
Now back in the Visual Studio Solution Explorer add a reference to the White.Core.dll to your project. Right click on the References folder and select Add Reference…
_thumb.png)
Figure 5: Add new Reference to White.Core.dll

Figure 6: In the Add Reference dialog go to the Browse tap and navigate to the White folder that is your projects bin directory
Once you start writing and running your automated tests from Visual Studio you will most likely encounter a "NonComVisibleBaseClass" exception. You can configure the debugger to ignore this exception.
Select the Debug –> Exceptions menu option in Visual Studio and expand the Managed Debug Assistants node, then uncheck the NonComVisibleBaseClass Thrown check box.

Figure 7: Un-check the NonComVisibleBaseClass managed debug assistant in Visual Studio
At this point your tools are ready for writing, testing and debugging White tests.
Resources
To learn about coding White tests refer to the White documentation and some White tutorials. The links are provided here:
White documentation
Is White the right choice?
Logical Layers of technology when using white.
Get Started and how to use different type of UIItems.
Programming using white
Configuration and Localization configuration.
Using with Continuous Integration
Wait Handling
Custom UI Item
Silverlight
Performance
UISpy
White.NUnit
Third Party Controls
Working with source
Useful tutorials
Custom Commands (Available after release 0.20)
Tutorials
http://blogs.msdn.com/b/john_daddamio/archive/2008/04/04/testing-wpf-applications-with-the-white-ui-test-framework.aspx
The discovery and automation workflow using UISpy
Use Ctrl + Mouse Click form UISpy to select and identify a WPF or Winform control. Use the AutomationId or the Name attribute and the SearchCriteria pattern in White to target the identified control.

Figure 8: Using UISpy to identify a control and retrieve the AutomationID or Name attribute
The common White coding pattern
A common way to target a control in white is to use the SearchCriteria object. Here is a code snippet that demonstrates this.
var searchCriteria = SearchCriteria.ByText("...");
var openFileDialogButton = importItems.Get<Button>(searchCriteria);
openFileDialogButton.Click();
The example
The following video shows the White automation example in action.
Here is the program code that drives the automation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.WindowItems;
using White.Core.UIItems.WindowStripControls;
using White.Core.UIItems.MenuItems;
using White.Core.UIItems.TreeItems;
using White.Core.UIItems.Finders;
namespace WhiteTest
{
class Program
{
static void Main(string[] args)
{
Application manager = Application.Launch(@"C:\Inetpub\wwwroot\Incuity\Download\IncuityManager.exe");
Window mainWindow = manager.GetWindow("VantagePoint Manager");
ExportSamples(mainWindow);
DeleteSamples(mainWindow);
ImportSamples(mainWindow);
System.Threading.Thread.Sleep(10000);
manager.Kill();
}
private static void ImportSamples(Window mainWindow)
{
var menuBar = mainWindow.MenuBar;
Menu importMenu = menuBar.MenuItem("File", "Import Items...");
importMenu.Click();
Window importItems = mainWindow.ModalWindow("Import Items");
var searchCriteria = SearchCriteria.ByText("...");
var openFileDialogButton = importItems.Get<Button>(searchCriteria);
openFileDialogButton.Click();
Window openDialog = importItems.ModalWindow("Open");
searchCriteria = SearchCriteria.ByAutomationId("1148");
var filePath = openDialog.Get<TextBox>(searchCriteria);
filePath.Text = @"C:\Inetpub\wwwroot\Incuity\Scripts\Samples.icp";
searchCriteria = SearchCriteria.ByText("Open");
var openButton = openDialog.Get<Button>(searchCriteria);
openButton.Click();
searchCriteria = SearchCriteria.ByText("Next >");
var nextButton = importItems.Get<Button>(searchCriteria);
nextButton.Click();
searchCriteria = SearchCriteria.ByText("Next >");
nextButton = importItems.Get<Button>(searchCriteria);
nextButton.Click();
System.Threading.Thread.Sleep(2000);
searchCriteria = SearchCriteria.ByText("Finish");
var finishButton = importItems.Get<Button>(searchCriteria);
finishButton.Click();
}
private static void ExportSamples(Window mainWindow)
{
var menuBar = mainWindow.MenuBar;
Menu exportMenu = menuBar.MenuItem("File", "Export Items...");
exportMenu.Click();
Window exportItems = mainWindow.ModalWindow("Export Items");
var searchCriteria = SearchCriteria.ByText("Samples");
var samples = exportItems.Get<TreeNode>(searchCriteria);
samples.Click();
searchCriteria = SearchCriteria.ByText(">");
var addButton = exportItems.Get<Button>(searchCriteria);
addButton.Click();
searchCriteria = SearchCriteria.ByText("Next >");
var nextButton = exportItems.Get<Button>(searchCriteria);
nextButton.Click();
searchCriteria = SearchCriteria.ByAutomationId("_filePathText");
var filePath = exportItems.Get<TextBox>(searchCriteria);
filePath.Text = @"C:\Inetpub\wwwroot\Incuity\Scripts\Samples.icp";
searchCriteria = SearchCriteria.ByText("Next >");
nextButton = exportItems.Get<Button>(searchCriteria);
nextButton.Click();
System.Threading.Thread.Sleep(2000);
searchCriteria = SearchCriteria.ByText("Finish");
var finishButton = exportItems.Get<Button>(searchCriteria);
finishButton.Click();
}
private static void DeleteSamples(Window mainWindow)
{
var searchCriteria = SearchCriteria.ByText("Samples");
var samples = mainWindow.Get<TreeNode>(searchCriteria);
samples.RightClick();
PopUpMenu popupMenu = mainWindow.Popup;
searchCriteria = SearchCriteria.ByText("Delete Item");
var deleteMenu = popupMenu.ItemBy(searchCriteria);
deleteMenu.Click();
Window deleteConfirmation = mainWindow.ModalWindow("VantagePoint");
searchCriteria = SearchCriteria.ByText("Yes");
var yesButton = deleteConfirmation.Get<Button>(searchCriteria);
yesButton.Click();
}
}
}
Download
The Visual Studio project for this example can be downloaded here: WhiteTest.zip
Ausblick
Ideally you would try to use a unit testing framework to drive the tests. I recommend looking into RSpec and IronRuby.