Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

White framework in Visual Studio for automation of WPF Application

In this topic, we will discuss on using White Framework in Visual Studio for automating a wpf application

To give an intro about white framework, this framework is .net based to automate win32/winform/wpf apps. Typically an object oriented API.

Tools/App used

  1. Solution name is WpfTestApplication
  2. download Snoop 2.8.0 from this is used for spying objects in UI
  3. Visual Studio
  4. Nuget Package – TestStack.White

Open the solution in visual studio and compile it to get the WpfTestApplication.exe. The app looks like the below


Snoop Tool

When you access our WpfTestApplication.exe, you need to refresh it by Clicking the button near the dropdown, and you see the mainwindow-wpftestapplication.


Steps for creating the automation project in VS

Create a new project by navigating to File -> New -> Project. Select Tests – Unit Test Project.


Add TestStack.white as reference by adding through manage nuget package.


Once you have installed the nuget package, you can see the below highlighted reference in the project.


How to find the property of an element.

We have the WPF application in the left side and Snoop Tool on the right side. When you select a checkbox in the application, you can view the properties/events/data context/methods associated with the control in the snoop tool as described in the screenshot below.


Sample Code looks like the below.


Once the testmethods are written, You can run the test in the test explorer. Right click on the method and click on ‘Run Selected Tests’.


As like any of the UI automation frameworks, white framework allows us to select an element using few properties as below.


Few Listed Properties.

Launch the application.

Use White.Application.Launch(app_path)

Getting the context of the mainwindow.

Window mainWindow = application.GetWindow(“MainWindow”);

Clicking on a Button 

TestStack.White.UIItems.Button btnbuttonintoolbar = mainWindow.Get(SearchCriteria.ByText("Button in toolbar"));

Clicking on a Tab

TestStack.White.UIItems.TabItems.TabPage tabInput = mainWindow.Get(SearchCriteria.ByText("Input Controls"));

Get the list of items in a listbox and selecting the first item.

ListBox lnumber = mainWindow.Get("ListBoxWithVScrollBar");

Get the list of items in a ComboBox and selecting the first item.

ComboBox cSelect = mainWindow.Get("AComboBox");

Clicking on a CheckBox

TestStack.White.UIItems.CheckBox chkSecond = mainWindow.Get(SearchCriteria.ByText("A checkbox"));

Inputting a text in a textbox.

TestStack.White.UIItems.TextBox txtBox = mainWindow.Get(SearchCriteria.ByAutomationId("TextBox"));
txtBox.Text="Hi This is a Text Box";

Clicking on a radio button

TestStack.White.UIItems.RadioButton rdoBtn1 = mainWindow.Get(SearchCriteria.ByAutomationId("RadioButton1"));

Clicking on a hyper link

TestStack.White.UIItems.Hyperlink hlink = mainWindow.Get(SearchCriteria.ByText("Link Text"));

Navigating through a slider

TestStack.White.UIItems.Slider sldrOne = mainWindow.Get(SearchCriteria.ByAutomationId("Slider"));

Expand a tree node

TestStack.White.UIItems.TreeItems.TreeNode nodeOne = mainWindow.Get(SearchCriteria.ByText("Root"));

Share the post

White framework in Visual Studio for automation of WPF Application


Subscribe to Msdn Blogs | Get The Latest Information, Insights, Announcements, And News From Microsoft Experts And Developers In The Msdn Blogs.

Get updates delivered right to your inbox!

Thank you for your subscription