Tool Review: WatiN
25. Dezember 2010 Hinterlasse einen Kommentar
Tool Review: WatiN
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#.
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.
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.
WatiN is available under the Apache License 2.0.
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
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:
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.
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.
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.
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.
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.
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.
About the Author
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: firstname.lastname@example.org