Click here to Skip to main content
15,881,172 members
Articles / WaTiN
Tip/Trick

Watin - An Automation Testing in .NET

Rate me:
Please Sign up or sign in to vote.
4.94/5 (8 votes)
25 Sep 2013CPOL4 min read 78.6K   18   8
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:

    Image 1

  • Add Console Application and name the project as displayed in the below screenshot:

    Image 2

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
Image 3

7.3 Creating the Test Script in Visual Studio:

Here, I am showing a test script which verifies the Maximum length of a textbox:

Image 4

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:

Image 5

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.

Image 6

This report is showing the success of the script, green color shows that the particular script has passed.

Image 7

License

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


Written By
Tester / Quality Assurance
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWatin Pin
Viresh Karshan30-Dec-14 21:57
Viresh Karshan30-Dec-14 21:57 
AnswerRe: Watin Pin
MinniPandey5-Jan-17 20:06
MinniPandey5-Jan-17 20:06 
AnswerHow to call Javascript method. Pin
MinniPandey17-Jul-14 21:00
MinniPandey17-Jul-14 21:00 
QuestionSouce code? Pin
leiyangge15-Jun-14 23:34
leiyangge15-Jun-14 23:34 
Any source code download?
QuestionHow to call Javascript method. Pin
dosh_harshal24-Jan-14 5:45
dosh_harshal24-Jan-14 5:45 
QuestionNice article to explain the basics of WatiN Pin
Thomas Han14-Nov-13 13:50
Thomas Han14-Nov-13 13:50 
AnswerRe: Nice article to explain the basics of WatiN Pin
MinniPandey14-Nov-13 19:34
MinniPandey14-Nov-13 19:34 
GeneralRe: Nice article to explain the basics of WatiN Pin
swapnilcodeproject21-Nov-13 22:53
swapnilcodeproject21-Nov-13 22: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.