Getting Started with WHITE .NET/WPF Automation Framework

by Joe Colantonio on November 26, 2012

Post image for Getting Started with WHITE .NET/WPF Automation Framework

An Open Source alternative to QTP?

Are you a QTP engineer that has often wished there was a way to automated .NET and WPF applications using Visual Studio and C# rather than QuickTest Professional? Do you need to automate a thick client application like WPF, Silverlight, Win32 or WinForms? If so, then WHITE might just be the automation framework for you.

Unlike QTP, which limits you to using VBScript, White allows you to create tests in whichever .NET language you wish -- in an IDE that you already use. All this in free open source software -- how sweet is that?

Okay. Sounds good so far, but which controls/technologies does it support?

White runs on top of the .NET UI Automation framework. (And just like with QTP, if your application uses third party controls you'll want to verify that WHITE supports them.) White also supports 32 and 64 bit Windows. For more info on what White support check out: Is White the right choice?

Sample .NET Application

I will be using a small .NET sample application I created in Visual Studio 2010 and creatively named.


UISPY

Before we can start automating our application we'll need a way to spy on the application's fields in order to get the identification properties we'll need to use in order for them to be recognized by WHITE. For this example, I'll use the UI Spy that's installed with the Microsoft Windows SDK. It's located in the \bin folder of the SDK installation path (uispy.exe), or can be accessed from the Start menu (Start\All Programs\Microsoft Windows SDK\Tools\UISpy).


If you start up the test application, then start UI Spy you'll see all the test application's controls in the UI Spy's Control View. The application will be in a tree view. Navigating through the tree view will reveal all your objects along with their properties that can be seen:


Installing the White Automation Framework using Visual Studio

  • First, navigate to the White Downloads page and grab the latest release.
  • Create a folder named White on your local drive and extract the downloaded zip files to it.
  • Open up Visual Studio and create a new .NET Framework 3.5 console application named WHITE.


    • In your new project, go to the Project>Add Reference menu option.
    • Click on Browse and add the White.Core.dll.



  • Add the following namespaces
    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;
    
    • To start an application, you must to use the Application.Launch method:
    Application application = Application.Launch(@"D:\Debug\JoeColantonioSampleApp.exe"
    


    • You can verify that your app has started by using the GetWindow method:

       

    Window window = application.GetWindow("JoeColantonio.Com Sample .Net App");
    


    • As with all automation tools, nothing will be very reliable if you don't use some sort of synchronization method to ensure your window/field is active before proceeding. To do this in the WHITE framework, you can use the WaitWhileBusy method:
    window.WaitWhileBusy();
    
    • Now we can interact with the fields in our application. Everything in White is a UIItem and has different subclasses that map to corresponding controls. So, to enter text into my application's Patient Name field, I would use the UIItem TextBox control type:
    var patName = window.Get<White.Core.UIItems.TextBox>(SearchCriteria.ByAutomationId("txtPatient"));
    patName.Enter(<span style="color:#a31515">"COLANTONIO,JOE"</span>);
    
    • When using WHITE, there are a few methods that can be used to identify objects in your application. The one I use most often is the ByAutomationID.

      The AutomationID is the programmatic ID assigned by the developer of the application. In Visual Studio this would be the Name property under the Design section:


     

    The completed script for entering data in all my application's fields looks like this:

    static void Main(string[] args){
     {
      Application application = Application.Launch(@"D:\Debug\JoeColantonioSampleApp.exe");   Window window = application.GetWindow("JoeColantonio.Com Sample .Net App");           window.WaitWhileBusy();
    var patName = window.Get<White.Core.UIItems.TextBox>(SearchCriteria.ByAutomationId("txtPatient"));
    patName.Enter("COLANTONIO,JOE");
    window.WaitWhileBusy();
    var p = window.Get<White.Core.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId("cboProvider"));
    p.Select("Crusher, Beverly");
    window.WaitWhileBusy();
    var dept = window.Get<White.Core.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId("cboDepartment"));
    dept.Select("Sickbay");
    window.WaitWhileBusy();
    var apptType = window.Get<White.Core.UIItems.ListBoxItems.ComboBox>(SearchCriteria.ByAutomationId("cboApptType"));
    apptType.Select("CON");
    window.WaitWhileBusy();
    var schedType = window.Get<White.Core.UIItems.RadioButton>(SearchCriteria.ByAutomationId("rdoSchedule"));
    schedType.Click();
    var button = window.Get<Button>(SearchCriteria.ByAutomationId("btnSubmit"));
    button.Click();
    var apptMsg = window.MessageBox("Appointment Confirmation");<br />
    


    A Simple Example and the Future of White

    This was a simple example to give you a taste of what can be done using the WHITE framework. I'll admit that I haven't tried it on a real-world application so at this stage I'm not sure how robust it really is.

    I also have concerns about how often this open source project is updated. The last release was the August 1, 2011 version 0.21, so development and enhancements for this project have been inactive for some time.

    The good news is there's a good chance that activity will soon increase on WHITE since it was recently acquired by TestStack.

{ 7 comments… read them below or add one }

malay April 15, 2013 at 11:16 am

Hi Joe,
Just logged in to ask you some open source tool to test windows applications, and see, I found this post.:-)you know it all.All thanks to you.
I am grateful.

Thanks,
Malay

Reply

Joe Colantonio April 18, 2013 at 1:08 pm

malay » Cool :) Nice the hear from you Malay!

Reply

malay April 20, 2013 at 12:56 pm

Hi Joe,

There is very less documentation available for White.Moreover,i dont see any of the DLLs mentioned in your post for White.Can you please suggest some good reading.

Reply

malay May 1, 2013 at 6:53 am

Gentle reminder Joe.Waiting for a response.

Help ! Help !

Reply

int May 4, 2013 at 3:27 am

malay:
you have to install White through from NuGet using the command:
PM> Install-Package TestStack.White

Here’s some other sites you should check out:
http://white.codeplex.com/documentation
http://www.codeproject.com/Articles/289028/White-An-UI-Automation-tool-for-windows-applicatio

Reply

pawan May 6, 2013 at 5:24 am

Thank you very much , after reading this post really it helped in understanding the concept

Reply

Joe Colantonio May 8, 2013 at 11:02 pm

pawan » Awesome – glad it helped!

Reply

Leave a Comment

Previous post:

Next post: