I am pretty proud of our WatiN stack, it is in it’s third major version now and is an absolute joy to work with.
After seeing some other’s code samples online I thought that I should share some of the details so people can improve what they are doing. We recently hit a new one day record with one of our SDE/T’s writing 72 new test cases in a single day.
How it works
Our stack is broken down into four key layers, the test, a logical layer, a physical layer and then WatiN itself. If we are working on a Winforms application, we replace WatiN with an in-house developed stack that uses the Windows UI automation API’s. Our test data is stored in a SQL express database and we have a generated data access layer, which keeps the cost of creating CRUD methods very low. One of our tests looks like this:
[TestMethod]
public void VerifyCustomerCreation()
{
Logical.Customer.CreateNewCustomer("Default Customer");
Verification.Customer.VerifyCustomerCreated();
}
And that’s it. The tests are written in the business domain of the application that we are testing, not in a pile of clicks and set values. The next level down the “logical” layer is called by the tests and looks like this:
public static void CreateNewCustomer(string customerName)
{
Physical.Customer.GoToNewCustomerPage();
Physical.Customer.EnterNewCustomerInfo(customerName);
Physical.Customer.SaveNewCustomer();
}
We build our logical layer up by combining smaller atomic actions, this allows us to heavily use the DRY (don’t repeat yourself) approach.
Our physical layer is where the rubber hits the road and it looks like this:
public static void EnterNewCustomerInfo(string customerName)
{
ControlHandler conroller = new ControlHandler();
TestData.Customer customerDetails = TestData.Customer.GetCustomerDetails(customerName);
controller.SetValue(NewCustomerPage.txtFirstName, customerDetails.FirstName);
controller.Invoke(NewCustomerPage.btnSave);
}
The control handler fully abstracts WatiN, or another automation tool so we interact with any control by typically only calling either SetValue, Invoke or GetValue.
To define our controls we have an in-house developed tool where we drag a magnifying glass (Spy++ style) onto a page and it then captures all the controls and gives us a generated static class.
This stack is the result of a lot of investment in our time and represents, in my opinion, state of the art when it comes to web test automation. But then again, I am a bit biased because I wrote it
.

July 10th, 2010 at 7:33 am
I am trying to get a grasp of this stack but am having difficulty implementing the ControlHandler. I am hoping that you can provide a snippet of ControlHandler.SetValue for a TextField. Thanks.
August 27th, 2010 at 4:11 pm
Hi
My website consist of a Wizard. It is an enhanced version of modal dialog. The wizard contain update panel, which has all the controls(and when next button is pressed, other control appear which also exist on that panel) It contains serveral controls(Like textboxes,buttons,checkboxes). I have tried to grab the controls but failed( use several techniques like ie.HtmlDialog,iFrame,WaitUntilExits,etc).
Actually WatiN does not realise that the page has actually refreshed therefore not be able to find the elements.
Plz Help !!!
I am stuck here.