Click here to Skip to main content
Click here to Skip to main content

Tagged as

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.

License

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

Share

About the Author

MinniPandey
Tester / Quality Assurance
India India
No Biography provided

Comments and Discussions

 
AnswerHow to call Javascript method. PinmemberMinniPandey17-Jul-14 21:00 
QuestionSouce code? Pinmemberleiyangge15-Jun-14 23:34 
QuestionHow to call Javascript method. Pinmemberdosh_harshal24-Jan-14 5:45 
QuestionNice article to explain the basics of WatiN PinmemberThomas Han14-Nov-13 13:50 
AnswerRe: Nice article to explain the basics of WatiN PinmemberMinniPandey14-Nov-13 19:34 
GeneralRe: Nice article to explain the basics of WatiN Pinmemberswapnilcodeproject21-Nov-13 22:53 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 25 Sep 2013
Article Copyright 2013 by MinniPandey
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid