Click here to Skip to main content
13,356,787 members (74,813 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


18 bookmarked
Posted 25 Sep 2013

Watin - An Automation Testing in .NET

, 25 Sep 2013
Rate this:
Please Sign up or sign in to vote.
Introduction to Watin

1. What Is WatiN?

1.1 Overview

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.

1.2 Technique

WatiN interacts with the Internet Explorer using its COM (Component Object Model) interface. The Firefox interaction is done using the JSSh (JavaScript Shell Server) extension for Mozilla Firefox, present in WatiN.Core.dll file.

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

  1. Visual Studio framework for writing the test scripts in C#
  2. 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 textbox:

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Tester / Quality Assurance
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionWatin Pin
Member 1134473630-Dec-14 22:57
memberMember 1134473630-Dec-14 22:57 
AnswerRe: Watin Pin
MinniPandey5-Jan-17 21:06
memberMinniPandey5-Jan-17 21:06 
AnswerHow to call Javascript method. Pin
MinniPandey17-Jul-14 22:00
memberMinniPandey17-Jul-14 22:00 
QuestionSouce code? Pin
leiyangge16-Jun-14 0:34
memberleiyangge16-Jun-14 0:34 
QuestionHow to call Javascript method. Pin
dosh_harshal24-Jan-14 6:45
memberdosh_harshal24-Jan-14 6:45 
QuestionNice article to explain the basics of WatiN Pin
Thomas Han14-Nov-13 14:50
memberThomas Han14-Nov-13 14:50 
I have used WatiN for testing web applications, and found the test scripts to be very easy to maintain. The problem I see is that the project development for WatiN seems to have stalled for about a year. Fortunately, most of my existing scripts work under IE 11, although some of the WatiN-injected JavaScript fails. So, it's in need of an upgrade. Is the source for WatiN available for revisions and changes by the open source community? It would be nice if those still interested in the project could keep it alive.
AnswerRe: Nice article to explain the basics of WatiN Pin
MinniPandey14-Nov-13 20:34
memberMinniPandey14-Nov-13 20:34 
GeneralRe: Nice article to explain the basics of WatiN Pin
swapnilcodeproject21-Nov-13 23:53
memberswapnilcodeproject21-Nov-13 23:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 25 Sep 2013
Article Copyright 2013 by MinniPandey
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid