How to use White

May 6, 2010 at 12:13 AM

Hi Folks,

I am completely new to this White Tool.

I have some basic questions about how to use this tool.

1)How and where can I write my TestCase and Run it?E.g In selenium I can record and run my testcase for webapplication.similarly where can I write and run my TestCases using White Tool

2)Is MS SDK  necessity for this tool or can I write and execute my testcases in White without SDK?

 

Thanks in Advance.

 

May 6, 2010 at 7:15 AM
Edited May 6, 2010 at 7:16 AM

Hi

download, the sources,  there is a sample included.

Look here for an other small sample : Sample

Note: you should change the usings from

"using Core...." to

"using White.Core..."

 

Have also a look here: Getting started

You can use any editor tro write your testcases, a good idea seems to be using MS Visual Studio and Resharper (resharper includes a test runner to run and debug test directly in Visual Studio) and Nunit (www.nunit.org) to run the tests and get a testresult.

 

I'm not sure for 2. but you need UIAutomation Referencesin some cases

 

Hope that helps

Throndorin

 

 

 

 

 

 

May 6, 2010 at 8:35 AM

Hi

Appreciate your help and Thanks.

 

But as a novice I stil could not start using White for Testing.

I will tell you what steps  Ihave done so far -

1)Installed the Nuni NUnit-2.5.5.10112.msi

2)Downloaded the source for white as  - White_Bin_019.zip and White_Src_18-1-2010 and unzip both the files in separate folders. (Is that correct?)

3) Downloaded the sample example from the also --- ListBoxExample.zip.

Now what should I do  to run and see the application.

Please tell step by step

 

 

Thanks in Advance!

 

 

 

May 6, 2010 at 10:37 AM
Edited May 6, 2010 at 10:37 AM

you need also the White binaray:

 

extract the binary zip on your PC.

 

open the ListBoxExample in VisualStudio, look that the references to the white dlls are correct, if not change the references.

 

the example is build with an older version so change all usings from Core to White.Core

 

build the example

 

open Nunit load the test DLL

 

run the tests

 

May 8, 2010 at 10:32 PM

Hi,

Please check my answers and queries below.

Can you please tell me about the questions?

 

Thanks in advance

########################################################################################################################################

you need also the White binaray:   - I have extracted White_Bin_0.19 and White_Src_18-1-2010.

 extract the binary zip on your PC.    ---

open the ListBoxExample in VisualStudio, look that the references to the white dlls are correct, if not change the references.

As per instruction I downloaded the Binary source and unzipped it.

I have visual studio .NET installed on my machine.

But when I try to open ListBoxExample.solution file or c# project file it does not open.

It gives me error that is not a valid project file.

 Please let me know which file should I open in Visual studio and how and where can I change the reference to the Whitedll.?

the example is build with an older version so change all usings from Core to White.Core

 build the example  -- Please tell me how can I build the example in VStudio.NET.

 open Nunit load the test DLL  --

I have installed the NUnit but can you please tell me How to open the NUNIT and  load the DLL?

run the tests

 

 

May 10, 2010 at 7:23 AM

Hi

 

first no idea why you can not open the example with Visual Studio, I have no problems only a warning that the projects are not trusted.

I use the ListBoxExample.sln to open the solution.

maybe try SharpDeveloper (free c# tool) to open the Solution.

 

=> Changing the references is easy: under the test project are 2 reverences (nunit.framework and White.Core), delete both references and add them new with the path to the extracted white binarys.

(White.Core.dll and nunit.framework.dll)

than:

replace UnitTests.cs content with the following:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Additional using statements
using NUnit.Framework;
using White.Core;
using White.Core.UIItems;
using White.Core.UIItems.WindowItems;
using White.Core.UIItems.ListBoxItems;
using White.Core.Factory;
using White.Core.WindowsAPI;

using System.IO;
using ListBoxExample;

namespace Tests
{
    [TestFixture]
    public class UnitTests
    {
        private Application application;
        private Window window;

        /// <summary>
        /// This test shows 
        /// 1. how to enter data using keyboard strokes and controls
        /// 2. how to select items in a list using an index number and a text string
        /// 3. how to check the results using White's Verify class which does stop the test if the results are wrong
        /// 4. how to start & stop the the app.
        /// 
        /// This example was linked with Release 0.14 of white. Replace the references to that release with the current release.
        /// </summary>
        [Test]
        public void AddPeopleTest()
        {
            try
            {
                // Start the app
                application = Application.Launch("ListBoxExample.exe");
                Assert.IsNotNull(application);

                // Find the main window
                window = (Window)application.GetWindow("Window1", InitializeOption.NoCache);
                Assert.IsNotNull(window);

                // Add a person using keyboard input
                White.Core.InputDevices.AttachedKeyboard keyboard = window.Keyboard;

                // Tab to the name textbox
                keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.TAB);
                // Type the name into the name text box
                keyboard.Enter("Harriet");

                // Tab to the combobox
                keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.TAB);
                // Type a g to select Girl
                keyboard.Enter("g");

                // Tab to the add button control
                keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.TAB);
                // Hit the Enter key
                keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.RETURN);

                string[] names = { "Tom", "Dad", "Mom", "Jane", };
                Genders[] genders = {Genders.Boy,Genders.Man,Genders.Woman,Genders.Girl, };
              
                // Add a person using White controls
                WPFComboBox comboBox = window.Get<WPFComboBox>("genderComboBox");
                Assert.IsNotNull(comboBox);
                TextBox nameTextBox = window.Get<TextBox>("nameBox");
                Assert.IsNotNull(nameTextBox);
                Button button = window.Get<Button>("addButton");
                Assert.IsNotNull(button);

                for (int i = 0; i < names.Length; i++)
                {
                    nameTextBox.Text = names[i];
                    comboBox.SetValue(genders[i]);
                    button.Click();
                }

                // Find the ListBox by its name
                ListBox theList = window.Get<ListBox>("theListBox");
                // Select the fourth item in the list by index; Like arrays, the index is from 0 to N-1
                theList.Select(3);

                // Find the detail info for the selected item (name and gender)
                Label selectedItemNameLabel = window.Get<Label>("selectedItemName");
                Assert.IsNotNull(selectedItemNameLabel);
                Label selectedItemGenderLabel = window.Get<Label>("selectedItemGender");
                Assert.IsNotNull(selectedItemGenderLabel);

                string errors = String.Empty;

                // The data should be Mom and Woman
                Assert.AreEqual("Mom", selectedItemNameLabel.Text);
                Assert.AreEqual(Genders.Woman.ToString(), selectedItemGenderLabel.Text);
                // Sleep so the user can see the example run
                System.Threading.Thread.Sleep(1000);

                // Select an item by the object's ToString text
                theList.Select("Harriet");
                // The data should be Harriet and Girl
                Assert.AreEqual("Harriet", selectedItemNameLabel.Text);
                Assert.AreEqual(Genders.Girl.ToString(), selectedItemGenderLabel.Text);
                // Sleep so the user can see the example run
                System.Threading.Thread.Sleep(1000);


            }
            finally
            {
                if ((application != null) && (application.HasExited == false))
                {
                    application.Kill();
                }
            }
        }


    }
}

build the solution

 

open Nunit

 

File=>Open Project

select the Tests.dll in ..\ListBoxExample\Tests\bin \Debug

there is only one test (AddPeopleTest)

 

start the test

 

 

 

May 20, 2010 at 8:13 AM
Edited May 20, 2010 at 8:13 AM
Hi, Thanks for the help. I did as per instruction and now I can open and run the ListBoxexample. Now I am trying to write the TestCase in the same UnitTest.cs. The purpose of my Testcase is -- 1) Open Excel 2007 ONLY and click on the the tab of PageLayout tab based on the keys. Please find my Testcase below. Once I run the testcase in NUNIT it opens the Excel sheet and that is perfect but after that it fails. It gives me the error at Stack trace ---- at White.Core.Factory.WindowFactory.FindWindowElement(Process process, String title) in d:\white\Core\Factory\WindowFactory.cs:line 44 at White.Core.Factory.WindowFactory.CreateWindow(String title, Process process, InitializeOption option, WindowSession windowSession) in d:\white\Core\Factory\WindowFactory.cs:line 97 at White.Core.Application.GetWindow(String title, InitializeOption option) in d:\white\Core\Application.cs:line 125 at Tests.UnitTests.ExcelOpen() in c:\Documents and Settings\ynaik\Desktop\White\ListBoxExample\ListBoxExample\Tests\UnitTests.cs:line 130 Tests.UnitTests.ExcelOpen: System.NullReferenceException : Object reference not set to an instance of an object. public void ExcelOpen() { try { application = Application.Launch("C:\\Documents and Settings\\All Users\\Start Menu\\Programs\\Microsoft Office\\Microsoft Office Excel 2007"); Assert.IsNotNull(application); System.Threading.Thread.Sleep(10000); // // Find the main window window = (Window)application.GetWindow("Microsoft Excel - Book1", InitializeOption.NoCache); Assert.IsNotNull(window); White.Core.InputDevices.AttachedKeyboard keyboard = window.Keyboard; keyboard.PressSpecialKey(KeyboardInput.SpecialKeys.ALT); keyboard.Enter("y"); keyboard.Enter("0"); keyboard.Enter("1"); } finally { if ((application != null) && (application.HasExited == false)) { application.Kill(); } } } CAN YOU PLEASE HELP ME TO REMOVE THIS ERRORS AND RUN THIS TESTCASE. Thanks in Advance
Coordinator
Jun 2, 2010 at 8:30 AM

Looks like it is a bug in white which is causing this.

application = Application.Launch("C:\Documents and Settings\All Users\Start Menu\Programs\Microsoft Office\Microsoft Office Excel 2007");

is returning application object which is not constructed right as the process object inside is null. Reason being the you are launching using a shortcut.

Coordinator
Jun 2, 2010 at 8:30 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.