Tool Review: WatiN

Tool Review: WatiN

WatiN Logo


WatiN (pronounced as What-in) enables .Net to interact with Internet Explorer 6, 7, 8 as well as FireFox 2 and 3. Inspired by WatiR, Jeroen van Menen started at the end of 2005 the development of WatiN to replace the commercial test application of his company. 2007 Edward Wilde joined the project and enabled WatiN to support FireFox. Furthermore he created WaX, a small framework that allows to create WatiN tests using Microsoft Excel.

The following review will focus on WatiN using C#.

Technique: Star2Star2Star2

WatiN interacts with the Internet Explorer using its COM interface. The FireFox interaction is done using the JSSh (JavaScript Shell Server) extension for Mozilla FireFox. Although the interaction technique for both of the browsers is different, the API of WatiN is not (in most cases). So, actually WatiN tries to hide the type of the automated browser to create browser independent tests. The disadvantage of this technique is, that this special bridge between WatiN and the automated browser has to be developed for every different browser and eventually must be changed when a new browser version gets launched.

Using a more or less native method to interact with the browser and the html controls has some advantages:

  • Neither the browser nor the displayed web site/web application gets changed to enable interaction. So testing with WatiN does not have any side affects.
  • The native interaction enables WatiN to read many details of the current state of the browser so for example WatiN is able to synchronize the test with the browser.

Documentation: Star2Star2

The documentation of WatiN is a bit outdated. The API reference on the other hand is complete and well structured. Also a well documented and illustrated Getting started article is available. A very helpful Mapping Table and FAQs are also available on the web site.

Support (Community/Commercial): Star2Star2Star2

Community support is available through the official mailing lists, and the bug/feature tracker. Furthermore professional support is possible through the developer Jeroen van Menen.

License: Star2Star2Star2

WatiN is available under the Apache License 2.0.

Installation: Star2Star2Star2

The installation of WatiN is easy and well documented. First download the latest release from sourceforge. The archive contains the binaries (WatiN.Core.dll) the source, some examples and the JSSh Plugin for FireFox. A ReadMe and a compiled help file are also inside the archive. Then you have to decide which IDE (for example the free Microsoft Visual Studio Express Edition) you want to use, because WatiN is just a library which can be used in every .Net language and in every .Net compatible IDE. I will use MSVS 2008 EE in this example.

After creating a new console application you have to link the WatiN.Core.dll to your project:

  • 1Menu: Project/Add Reference
  • Navigate to the „Browse“ tab and open the the „WatiN.Core.dll“
  • Accept by clicking „OK“
  • If you reopen the dialog and navigate to the „Recent“ tab you will see the referenced dll

Reference the WatiN DLL in MSVC

The next important thing is to add the line „[STAThread]“ to your class (read more why this is important). Now you can begin to write your tests with WatiN.

Handling & Usability: Star2Star2

WatiN is just a .Net library, so the only way to use it is by developing an own test project using a .Net compatible language. The API of WatiN is very easy to use so even a non professional software developer should be able to understand and use it quickly.

So even the API of WatiN is easy to use, WatiN does not provide any help to create automated browser tests. No real (i will mention WatiN Test Recorder later) Capture & Replay possibility is available and no tool to reveal the details of an element of the web site to automate exists. So, WatiN says „Don’t forget to download the Internet Explorer Developer Toolbar (not compatible to IE 8, use the developer tools included) or Firebug for FireFox. This will help tremendously in exploring the structure of a webpage so you can create your test automation more easily.“ and this is indeed a good advice. These tools help you to identify the elements (links, buttons, input fields,…) of a web page.

Get the details of an element

With this information it is quite easy to automate a test. First create a new browser instance or attach the test to an existing browser.

Then try to „spy“ the web page element to interact with using the installed MS IE Developer Toolbar. Use the „id“ or „name“ tag to uniquely identify the element. Then use the Mapping Table to map the web element to the appropriate WatiN statement. To identify the element using WatiN you have to use one of its built in Find.By methods for example Find.ByID or Find.ByName. Continue these steps to create a simple web test.

WatiN on its own does not offer for example an automatically generated report or an overview, which steps passed and which failed. Therefore you have to deal with this on your own if you want such functionality.

Creating tests without the possibility of a capture tool has (at least) one major disadvantage: You have to take care of all interaction yourself. On simple web sites the interaction is focused on clicking links or buttons and type some text into fields. The creation of the tests is simple as well. But nowadays many web sites use AJAX more or less and sometimes automating web sites with AJAX can get a real challenge. Some events have to be fired manually using Element.FireEvent to achieve the same result as a normal user would get. To find these events the creator has to understand HTML/JavaScript very well.

Predefined Functionality: Star2Star2

WatiN offers everything you need to automate the web browser, but not much more. However the given functionality is easy to use. Synchronization with the browser gets done automatically for example by using Element.Click method (Element.ClickNoWait offers no synchronization if needed) or explicit by using Element.WaitUntilExists. Verification is done via the various properties of each WatiN element for example TextField.Text. However WatiN offers no functionality beside the browser interaction.

Data-Driven-Testing: Star2Star2Star2

WatiN on its own is not designed for Data-Driven-Testing. But because of the use of .Net this feature could be implemented. Furthermore a WatiN FitNesse fixture is available.

Compatibility: Star2Star2

WatiN is compatible to Internet Explorer 6, 7, 8 and FireFox 2 and 3. It is officially limited to Microsoft Windows and .Net > 2.0. Unofficially some attempts were made to bring WatiN to Mac OSX running with Mono but they are not fully usable yet.

Conclusion: Star2Star2Star2_3

Overall WatiN is a great help for creating automated browser tests in .Net, especially when you are already confident with .Net. Although the functionality is limited, it offers everything you need to interact with the browser.

Creating tests could be difficult because a capture tool is missing. So, sometimes doing the same things with WatiN a normal user would do is a bit tricky, but mostly possible.

WatiN Test Recorder

As mentioned earlier WatiN does not offer a capture tool, but someone else does. The tool is called WatiN Test Recorder and is designed to capture browser interaction and to create WatiN compatible source code.

Important links:

About the Author

klemens loschy

Klemens Loschy is member of SEQIS – The Austrian Test Experts! since 2002 and is responsible for test automation, load & performance tests, test frameworks and test tool development. Furthermore he is a student at the Technical University of Vienna (Software Engineering). He has more than 9 years experience with all kind of test software (automation and management) and programming languages (Java, SenseTalk, TSL, …).

Feel free to conctact him:


Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

Du kommentierst mit Deinem Abmelden / Ändern )


Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )


Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s

%d Bloggern gefällt das: