The White Windows UI automation getting started tutorial for testers

by Klaus Graefensteiner 7. October 2010 10:53


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:


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: 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.


The White open source project is hosted on CodePlex. Download the latest release and un-zip it. Here is the project and download link:

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…

WhiteTest - Microsoft Visual Studio (2)

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.


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
Third Party Controls
Working with source
Useful tutorials
Custom Commands (Available after release 0.20)


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);

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");





        private static void ImportSamples(Window mainWindow)
            var menuBar = mainWindow.MenuBar;
            Menu importMenu = menuBar.MenuItem("File", "Import Items...");


            Window importItems = mainWindow.ModalWindow("Import Items");

            var searchCriteria = SearchCriteria.ByText("...");
            var openFileDialogButton = importItems.Get<Button>(searchCriteria);

            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);

            searchCriteria = SearchCriteria.ByText("Next >");
            var nextButton = importItems.Get<Button>(searchCriteria);

            searchCriteria = SearchCriteria.ByText("Next >");
            nextButton = importItems.Get<Button>(searchCriteria);


            searchCriteria = SearchCriteria.ByText("Finish");
            var finishButton = importItems.Get<Button>(searchCriteria);

        private static void ExportSamples(Window mainWindow)
            var menuBar = mainWindow.MenuBar;
            Menu exportMenu = menuBar.MenuItem("File", "Export Items...");


            Window exportItems = mainWindow.ModalWindow("Export Items");

            var searchCriteria = SearchCriteria.ByText("Samples");
            var samples = exportItems.Get<TreeNode>(searchCriteria);

            searchCriteria = SearchCriteria.ByText(">");
            var addButton = exportItems.Get<Button>(searchCriteria);

            searchCriteria = SearchCriteria.ByText("Next >");
            var nextButton = exportItems.Get<Button>(searchCriteria);
            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);


            searchCriteria = SearchCriteria.ByText("Finish");
            var finishButton = exportItems.Get<Button>(searchCriteria);

        private static void DeleteSamples(Window mainWindow)
            var searchCriteria = SearchCriteria.ByText("Samples");
            var samples = mainWindow.Get<TreeNode>(searchCriteria);

            PopUpMenu popupMenu = mainWindow.Popup;
            searchCriteria = SearchCriteria.ByText("Delete Item");
            var deleteMenu = popupMenu.ItemBy(searchCriteria);


            Window deleteConfirmation = mainWindow.ModalWindow("VantagePoint");
            searchCriteria = SearchCriteria.ByText("Yes");
            var yesButton = deleteConfirmation.Get<Button>(searchCriteria);


The Visual Studio project for this example can be downloaded here:


Ideally you would try to use a unit testing framework to drive the tests. I recommend looking into RSpec and IronRuby.

Tags: , , , , , ,

WPF | Test Automation | C# | Silverlight

About Klaus Graefensteiner

I like the programming of machines.

Add to Google Reader or Homepage

LinkedIn FacebookTwitter View Klaus Graefensteiner's profile on Technorati
Klaus Graefensteiner

Klaus Graefensteiner
works as Developer In Test and is founder of the PowerShell Unit Testing Framework PSUnit. More...

Open Source Projects

PSUnit is a Unit Testing framwork for PowerShell. It is designed for simplicity and hosted by Codeplex.
BlogShell is The tool for lazy developers who like to automate the composition of blog content during the writing of a blog post. It is hosted by CodePlex.



Powered by:

Creative Commons License

© Copyright 2015, Klaus Graefensteiner.

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Theme design:
This blog theme was designed and is copyrighted 2015 by Klaus Graefensteiner

Page rendered at 5/26/2015 12:28:45 AM (PST Pacific Standard Time UTC DST -7)