1. What Is WatiN?
WatiN stands for “Web Application Testing in .NET”, and is derived from WaTiR which is “Web Application Testing in Ruby”.
WatiN framework provides the Web Application testing through Internet Explorer however it supports Firefox as well. It supports the Internet Explorer 6, 7, 8 and Internet Explorer 9 version and Firefox 2.x and 3.x version.
It has Open source library and is known for very easy to read syntax.
WatiN is developed in C# and aims to bring you an easy way to automate your tests.
JSSH is a plug-in that exposes a telnet server that allows automation commands to be pushed to Firefox. When WatiN is downloaded, then it contains archive which have WatiN.Core.dll file.
The way that WatiN works is very "easy". WatiN lets you open Internet Explorer instances interact with the elements in a form. With WatiN, you can get and set values from the elements in a form, and you can fire events of any of the elements.
2. Why WatiN?
Today, it is not difficult to test the code. A lot of tools (NUnit) are available in the market for testing the code. But if we are talking about Web Applications, then there comes an important layer which we never ignore, that is UI layer.
One of the issues faced when writing automation for the controls in UI and then checking the functionality. Sometimes, it happens that our test fails because the automated test is unable to find the control in the application.
In-spite of the fact that the developer has added it, a good way is to use WatiN classes and make it automated.
3. Pre-requisites for WatiN
- Visual Studio framework for writing the test scripts in C#
- NUnit or Gallio Test Runner for executing the test scripts
4. Scope of WatiN
Using Watin, we can do the following testing in ASP.NET web application:
- GUI Testing
- Functional Testing
- Regression Testing
5. Features/Benefits of WatiN
Following are the features of WatiN:
- Automate all the HTML elements
- Find elements by multiple attributes
- Support Ajax Website Testing
- Syntax of WatiN is more Object Oriented and intuitive for developers
- Supports creating screenshot of WebPages
- Easy to integrate with your favorite Unit Testing Tool
- Can be used with any .NET language
- Since it is open source, you can download and add new features yourself
6. Limitation of WatiN
Following are the limitation of WatiN:
- Ajax handling and Silverlight automation
- One drawback of the WatiN framework is that HTTP status codes are not exposed, which is currently a limitation of the COM automation in Internet Explorer.
- If you are running IE7 upwards, it includes a “feature” called Protected Mode. This mode causes problems when WatiN attempts to access the web page. As such, it is wise to disable this via the internet security settings for the browser. NOTE: This can lead to security problems.
- If you’re missing the core WatiN assembly, then you will get compile time errors; however, if you’re missing a reference to
SHDocVw, you receive runtime errors and your tests fail.
7. Demo of WatiN
7.1 Creating a Project
- Add the new Project in Visual Studio as displayed in the below screenshot:
- Add Console Application and name the project as displayed in the below screenshot:
7.2 Adding DLL Files
- Add the reference WatiN.Core.dll comes with WatiN Archive folder when it is downloaded
- Add the reference
nunit.Framework comes with NUnit framework, if you want to execute the script in NUnit framework
- Add the reference Gallio and MbUnit comes with Gallio framework, if you want to execute the script in Gallio framework
7.3 Creating the Test Script in Visual Studio:
Here, I am showing a test script which verifies the Maximum length of a
7.4 Execute the Script in Gallio Test Runner
This report is showing the failure of script, red color shows that the particular script has failed:
Here, I am displaying the Test Explorer which is the
treeview of the currently loaded tests which displays at the right of the Test Report.
This report is showing the success of the script, green color shows that the particular script has passed.