Several weeks ago I used WatiN (pronounced as What-in) to create a suite of automated GUI tests for an old internal ASP application that we were upgrading. Inspired by the popular ruby testing tool Watir, WatiN is an open source .NET wrapper around the Internet Explorer that you can reference in your test project and use to get access to all of the HTML elements on a web page. I was surpised by how easy it was to simulate a user typing text and clicking buttons and then check to see if the result page contained certain text. The following popular example code demonstrates how you would test a google search for WatiN.
public void SearchForWatiNOnGoogle()
using (IE ie = new IE("http://www.google.com"))
Today, I experimented with the IEDevToolbar for the first time and suddenly WatiN became much more compelling. By using the "Select Element By Click" feature under the Find menu in the IEDevToolbar, you can simply click on an element on a web page and instantly see all of its properties. Since most popular commercial sites have very large, chaotic source files with elements that don't always have ID or Name properties, this feature is indispensible when trying to figure out how to programmatically interact with the page. Below shows how I was able to retrieve the Starbucks stock price from CNN and create a test to ensure that it was above an acceptable amount.
Since the stock retrieval button on cnn.com was an image that had no name or ID, I used the Find.ByCustom() method to retrieve and click on the button using the className attribute.
This task would be even easier using the WatiN Test Recorder, which you can see in this flash demo. However, I still haven't been able to get the recorder to work properly on my Vista machine so I'm not a big fan of this tool yet. I will definitely keep an eye out for future versions though.