CarmaBlog

Agility, Java programming, New technologies and more…
  • rss
  • Home
  • Management
  • Agile Programming
  • Technology
  • Linux
  • Event
  • Contact
  • About the author
  • English
  • Francais

WatiN, an automation web testing tool

Fabian Piau | Wednesday June 10th, 2009 - 10:28 AM
685 views
  • Twitter
  • Facebook
  • Google +1
  • LinkedIn

A few days ago, I discovered a kind of tools that enables you to test web applications.

WatiN (pronounced as what-in) is a .NET GUI automation framework.

By using WatiN and programming a little, you only need to execute a program and be able to surf the internet without having to surf! You got it? No? Let’s go for some explanations.

Why don’t you “automate” your everyday life? Things you often do when you surf the internet.

This software reproduces, word for word, the workflow you have programmed. Automated actions are various: click on a button, select a value in a list, capture a screenshot, save the page and so on.

The programming language is C#. If you are already familiar with Java programming, C# would be easy to understand.

I am not Microsoft addict and I am used to Eclipse but I have to admit that Microsoft Visual Studio is a great IDE. After 2 or 3 days, you get used to it and create good automation scenarios.

Technically, to “find” these buttons, lists and other HTML elements, WatiN navigates in the HTML DOM tree structure of web pages (in other words, the tags).
WatiN can interact with a lot of HTML elements (see the HTML mapping list here).
WatiN identifies elements by their id, name, class, text, url, value, style… depending on your code.

To understand, the following is our first example:

public void login()
{
   // Open a new Internet Explorer Window and
   // goto a secured website
   ie = new IE("http://www.my-secured-website.com/login.php");

   // Find the user name text field and type "toto" in it
   ie.TextField(Find.ByName("username")).TypeText("toto");

   // Find the password text field and type "titi" in it
   ie.TextField(Find.ByName("password")).TypeText("titi");

   // Select the database
   ie.SelectList(Find.ByName("userDb")).SelectByValue("db2");

   // Click on the login button to connect
   ie.Button("loginId").Click();
}

This funtion automates the connection to a web application.

And here is the HTML code of the tested page (login.php):

<html>

<head>
</head>

<body>
    <table>
        <tr>
            <td width="100">User Name</td>
            <td>
                <input value="" maxlength="50" name="username" type="text">
            </td>
        </tr>
        <tr>
            <td>Password</td>
            <td>
               <input maxlength="50" name="password" type="password">
            </td>
        </tr>
        <tr>
            <td>Database</td>
            <td>
                <select name="userDb">
                  <option selected value="#">Select a database</option>
                  <option value="db1">DataBase 1</option>
                  <option value="db2">DataBase 2</option>
                  <option value="db3">DataBase 3</option>
                  <option value="db4">DataBase 4</option>
                </select>
            </td>
        </tr>
        <tr height="30"><td></td></tr>
        <tr>
            <td>
                <input name="login" id="loginId" type="button" value="Login">
            </td>
        </tr>
    </table>
</body>

</html>

What’s happening during the execution?

WatiN opens Internet Explorer, goes to the specified URL, looks for the text field named “username” and types “toto” in it. It does the same thing for the password.
Then, it selects a database in the list named “userDb” and finally, submits the form by clicking on the button identified by “loginId”.

Login page

At this point, WatiN is going to select the database and connect the user.
WatiN colors the current element it interacts with (that’s the yellow flashing).

In this example, Internet Explorer (ie) is used but WatiN supports also Firefox.

You can use the WatiN Test Recorder tool to generate code compatible with WatiN. Link here.
Perhaps, you will need to slightly modify the generated code for some optimizations, but this is really a good starting point.

Watin Test recorder Demo

A second example: a Google search (3 lines of code needed)

// Open an new Internet Explorer Window and
// goto the google website
IE ie = new IE("http://www.google.com");
 
// Find the search text field and type "how to use watin" in it
ie.TextField(Find.ByName("q")).TypeText("how to use watin");

// Click on the Google search button
ie.Button(Find.ByName("btnG")).Click();

Example stops here, but we can imagine a processing of the results.

Related posts

LaunchyLaunchy, applications launcher
Comments
1 Comment »
Categories
Agile programming
Tags
.net, automation, c#, gui test, watin
Comments rss Comments rss
Page 1 of 11

Language

  • Français
  • English

Most viewed posts

  • Changing the language in Firefox - 18,907 views
  • Java EE & CDI vs. Spring - 10,091 views
  • Customizing Gnome 3 (Shell) - 8,228 views
  • Firefox Nightly, Aurora, Beta, Desktop, Mobile, ESR & Co. - 6,028 views
  • WordPress plugins of CarmaBlog - 5,379 views
  • Open Street Map, better map than Google Maps? - 3,143 views
  • This file is currently used, you cannot do anything… Thanks you Windows ! - 2,912 views
  • Belbin – Team Role Theory - 2,397 views
  • Using Google Docs to create an online survey - 2,077 views
  • Changing the Eclipse splash screen in few seconds - 2,019 views

Tags

script shortcut google docjax best practices unmount plugin wordpress continuous integration ubuntu firefox eject mobile computing tool documents search engine extreme programming configuration management tdd automation jug bash ci chrome jquery .net wave windows seven sharing extension ebook nantes mongodb hard drive build watin java agile windows 7 nosql cloud unit test eclipse hibernate fosdem agility itil test blog training c#

Recent Posts

  • Get the opportunity to start a course about Gamification Tuesday April 2nd, 2013
  • Comparing NoSQL: Couchbase & MongoDB Friday March 8th, 2013
  • IconFinder, find efficiently your icons Friday March 1st, 2013
  • Fosdem 2013 Impressions Wednesday February 20th, 2013
  • Fosdem, a truly open conference Monday January 28th, 2013
  • Free online MongoDB training Tuesday January 1st, 2013
  • Discover Maxthon Tuesday December 11th, 2012
  • Shutdown, standby or hibernate your computer? Sunday December 9th, 2012
  • A mobile version of your WordPress Blog Sunday October 28th, 2012
  • Using Google Docs to create an online survey Monday September 24th, 2012
  • Open Street Map, better map than Google Maps? Wednesday July 25th, 2012
  • First steps with Apache Camel Friday May 11th, 2012
  • This file is currently used, you cannot do anything… Thanks you Windows ! Sunday April 22nd, 2012
  • Customizing Gnome 3 (Shell) Thursday March 15th, 2012
  • Give your application a facelift – CSS Wednesday February 15th, 2012

RSS feeds

RSS Feed RSS - Posts

RSS Feed RSS - Comments

Email Subscription

Enter your email address to receive notifications of new posts.

Links

  • Agile Nantes
  • Blog Ippon Technologies
  • Blog Netapsys
  • Blog Xebia France
  • Blog Zenika
  • Coursera
  • Developpef
  • Le Touilleur Express
  • Les Cast Codeurs Podcast
  • new Blog( perso );
  • OCTO talks !
  • The Coder's Breakfast

Follow me!

Follow me on TwitterFollow me on LinkedInFollow me on Google+Follow me on About.meFollow me on SlideShare

Categories

  • Event (9)
  • Linux (3)
  • Management (4)
  • Agile programming (11)
  • Technology (26)

Archives

  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (1)
  • January 2013 (2)
  • December 2012 (2)
  • October 2012 (1)
  • September 2012 (1)
  • July 2012 (1)
  • May 2012 (1)
  • April 2012 (1)
  • March 2012 (1)
  • February 2012 (1)
  • January 2012 (2)
  • December 2011 (1)
  • November 2011 (2)
  • October 2011 (2)
  • September 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • April 2011 (1)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • November 2010 (2)
  • September 2010 (1)
  • August 2010 (1)
  • July 2010 (1)
  • June 2010 (1)
  • May 2010 (1)
  • April 2010 (1)
  • March 2010 (1)
  • February 2010 (1)
  • December 2009 (1)
  • November 2009 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (3)
  • July 2009 (1)
  • June 2009 (2)
rss Comments rss get firefox
Fabian Piau | Copyright © 2009 - 2013
All Rights Reserved | Top ↑