White.NUnit as UI Testing tool

Got suggestion from JP, looking at White.NUnit as our UI testing tool, I’m surprised that it didn’t take too long to figure it out:

First difference this is different than Phantom UI test is, we have to write test cases in VS which we love to. Here is the sample code to test the calculator.

using NUnit.Framework;
using White.Core;
using White.Core.Factory;
using White.Core.UIItems;
using White.Core.UIItems.Finders;
using White.Core.UIItems.WindowItems;

namespace solution
{
    [TestFixture]
    public class CalcTests
    {
        private Application application;

        [SetUp]
        public void Setup()
        {
            application = Application.Launch("calc.exe");
        }

        [TearDown]
        public void TearDown()
        {
            application.Kill();
        }

        [Test]
        public void should_launch_calculator()
        {
             Assert.IsNotNull(application);
        }

        [Test]
        public void should_do_a_simple_add_operation()
        {

            Window window = application.GetWindow("Calculator", InitializeOption.NoCache);

            window.Get<Button>("1").Click();
            var result = window.Get<Label>(SearchCriteria.ByText("1"));
            window.Get<Button>("Add").Click();
            window.Get<Button>("3").Click();
            window.Get<Button>("Equals").Click();

            Assert.AreEqual("4", result.Text);

        }
    }
}

Hint:

  1. use White.recorder generate class function to get the actual control name.
  2. use SearchCriteria to find the control.

I found that White doesn’t know Datawindow control. For PB developer,they have to turn to IBM rational Robot or HP QuickTestPro, and learn another test script language other than C#.

Advertisements