I’ve been looking at testing WPF (Windows Presentation Foundation) applications lately. It took me a while to warm up to WPF apps but now I’m a big fan. UI automation for WPF apps is a new ball game. By far the best approach is to use the Microsoft UI Automation (MUIA) library which, like WPF, is part of the .NET 3.0 Framework. One thing I especially about WPF applications is the new Menu control model. Classic WinForms use a completely separate model for the main application menu and non-menu user controls. The idea was back then that menu-ing was really hooking directly into low-level Windows API functions so the menu control model should be different from the model forother user controls. See the screenshot below for an example of automating WPF Menu controls. Then at some point .NET revised the menu model (I think in .NET Framework 2.0 as I recall) to use a menuStrip control but this just added mild confusion (to me anyway). But WPF applications treat Menu controls just like any other user controls. This makes them much easier to automate than classic WinForm, non-WPF, menu controls. Unfortunately, in Visual Studio 2008 there is no built in support for drag-and-drop design for menu controls so you have to code the XAML by hand. But it’s not hard. For example, the automation in the screenshot below is exercising a WPF app with this menu XAML I added by hand:
<Menu Height="22" Name="menu1"
VerticalAlignment="Top" IsMainMenu="True" >
<MenuItem Header="_File">
<MenuItem Header="_New" Name="fileNew" />
<MenuItem Header="_Open" Name="fileOpen" />
<Separator />
<MenuItem Header="E_xit" Name="fileExit"
InputGestureText="Alt-F4" ToolTip="Exit StatCalc"
Click="OnFileExit" />
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="Help Topics" />
<Separator />
<MenuItem Header="About StatCalc" />
</MenuItem>
</Menu>
VerticalAlignment="Top" IsMainMenu="True" >
<MenuItem Header="_File">
<MenuItem Header="_New" Name="fileNew" />
<MenuItem Header="_Open" Name="fileOpen" />
<Separator />
<MenuItem Header="E_xit" Name="fileExit"
InputGestureText="Alt-F4" ToolTip="Exit StatCalc"
Click="OnFileExit" />
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="Help Topics" />
<Separator />
<MenuItem Header="About StatCalc" />
</MenuItem>
</Menu>
Notice the Click="OnFileExit" in the UI design. At compile time this will generate a C# method:
public void OnFileExit(object sender, RoutedEventArgs e)
{
// TODO
}
{
// TODO
}
and you can simply add: this.Close(); to the method body. Neat. Anyway, test automation for WPF apps is very interesting. I am writing up an article for MSDN Magazine that addresses all the key issues.
.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2026 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2026 G2E Conference
2026 iSC West Conference