≡ Menu
Joe Colantonio – Selenium-UFT-QTP-SoapUI-ALM-LoadRunner & more

Getting Started with WHITE .NET/WPF Automation Framework

Getting Started with WHITE .NET/WPF Automation Framework post image

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.

13 comments… add one

  • malay April 15, 2013, 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

  • malay April 20, 2013, 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.

  • malay May 1, 2013, 6:53 am

    Gentle reminder Joe.Waiting for a response.

    Help ! Help !

  • int May 4, 2013, 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

  • pawan May 6, 2013, 5:24 am

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

  • Ahad May 27, 2013, 3:17 pm

    Hi Joe when i’m trying to run my application by calling application.launch it is giving me an error message APPLICATION CANNOT EXECUTE WITH READ_ONLY ACCESS RIGHTS , do you ever encounter such rights issue.

  • Lam Ho July 8, 2013, 7:37 am

    I use your method to get Lync Basic 2013 of Microsoft. However, it can’t get a instance of an object . it was stated “Object reference not set to an instance of an object.”

    Do you have any suggest about this issue?

  • samy July 31, 2013, 6:00 pm

    great post, it help me a lot.
    I have a Qustion:
    can I make a test script to a 3third party app, without knowing the name of the controls veriables/objects?

    • Joe Colantonio September 2, 2013, 10:22 pm

      Hi Samy – sorry for my late response. Did you resolve this? Not sure I understand your question – are you saying that you are unable to find a unique id to use to identify the fields in the application?

  • Pranjal R Nigam February 5, 2014, 12:29 pm

    Hi Joe,

    As shown above you have applied an ‘.exe’ in the ‘Application.Launch’. What should I do if I have a ‘.xbap’ URL?

    Thanks
    Pranjal R Nigam

Leave a Comment

css.php