March 05, 2007

I really like WatiN

Over the last couple of months we've talked about the need to get some UI testing in place for some of the projects that I work on daily. I considered Selenium and spent a little time looking at Watir. As I started getting into Watir I realized that understanding and implementing it would take some time on my part and I set it aside for another day.

Early last week I was asked about UI testing again and coupled with my overhearing a mention of how much someone liked using WatiN at the Dayton .NET Developer's Group I decided to give it a look. Friday I downloaded and began playing with it and I was surprised how easy it was to implement. For me, the overhead in using WatiN is much, much less than Watir. It probably took me less than 30 minutes to download it, check out some examples and get some tests running.

To set up a WatiN test you:

  1. add a reference to the NUnit.Framework dll (or unit testing tool of your choice),
  2. add a reference to the WatiN.Core dll
  3. write some tests. Example:

    public void TestLogin() {
        using (IE ie = new IE(“http://localhost/somesite/”)) {
            //Fill in login info and submit the login form
            ie.TextField("txtUsername").Value = "myusername";
            ie.TextField("txtPassword").Value = "mypassword";
            //Should be redirected back to the home page, check for expected text
            Assert.IsTrue(ie.ContainsText("Expected text"), "Unsucessful login");

  4. Run your tests.

That's all there is to it. No installing Ruby, no installing Watir, no wiring up a bunch of other stuff to get Watir to run in NUnit or as part of an automated build.

When necessary, to help with the WatiN scripting I have used WatirRecorder++. WatirRecorder++ outputs script to be used by Ruby, but it wasn't too tough for me to translate to C# code - the WatiN developers have done a pretty good job of sticking to the Watir API. There is a port of WatirRecorder++ to WatiNRecorder, but it doesn't appear to be active and I have read requests for the source that appear to be unanswered.

There are some threading issues that need to addressed with NUnit, other testing frameworks and other programs using WatiN. I was able to work around each of those easily enough when running the tests in Visual Studio, with Resharper's Test Runner, or via the NUnit console or command line.   

However, the one thing I haven't been able to address is getting the WatiN NUnit tests running under Cruise Control.NET. The above mentioned fixes for NUnit did not seem to help when running under Cruise Control. If I run the test manually via the command line then they works fine. If I run the tests in Cruise Control via NAnt I get the ThreadStateException. I have read a couple of comments on the WatiN Sourceforge site and in some forum postings where some claim to have gotten it working in CC.NET, but I have not seen any examples, descriptions, or other details yet. Hopefully this issue will get corrected soon otherwise I'll have to look elsewhere for UI testing. It will not help me all that much to have good UI tests in place that will not run in my CI process.


  • Trackbacks,
  • and Pingbacks
  1.  avatar Alex says:

    You can also check SWExplorerAutomation SWEA from SWEA records, replays and generates C# or VB.NET script code. SWEA can run IE under user account (with user profile) different from the script account (service account, no user profile loaded). It allows SWEA scripts to be run from CC.NET. SWEA was specially designed to automate complex DHTML/AJAX applications.

  2.  avatar says:

    Thanks for the info, Alex.

  3. Hi Dan,

    Great to read your positive blog about WatiN. I run all the WatiN builds with CC.Net and Nant and have no problems with it. I have a WatiN.Core.UnitTests.dll.config file in the same directory the WatiN.Core.UnitTests.dll is in. The contents of the config for NUnit is the same when running your tests with resharper/testdriven/nunit (as mentioned in the WatiN site). The only problem you might run into is that the WatiN tests need a desktop when automating dialogs like java alert and confirm, fileupload e.a. This rules out running CC.Net as a service so in this case you need to start CC.Net from the commandline.

    Hope this info helps. If you have more questions drop a message on the watin-users mailing list.

    Jeroen van Menen

  4.  avatar says:

    Jeroen, thanks for the clarification. I will have to give my implementation a further look. I had read your comments before about not being able to run it as a service so I had been running it via the command line. Thanks,


  5. Hi there,

    Can you just clarify how you implemented getting Watin tests to run under Cruise Control. (have you had any success? - as per Jeroen's comments,I have the STA stuff configured in an appropriately named config file)

    Mine just seem to hang, till the timeout expires:I can see an instance of IE in memory, and nunit-console.exe but no tests get run. If I run from the command line, my tests run.

    I am using basic CC build configuration scripts, not Nant tasks...

  6.  avatar says:

    Matthew, I explained in a followup post what I did that corrected the issue:



  7.  avatar Keshav says:

    hi ,

    I currently have a table column, on click of that column header , all the items under that column are sorted in ascending or dsecnding order.

    .This table colummn header link button makes use of AJAX to do the post back.

    Now i not getting a way to wait untill the completion of the post back. i tried the following steps

    Link myLink = table.Link(Find.ByText(new Regex(columnName)));



    then didnt work. Again i tried with

    Link myLink = table.Link(Find.ByText(new Regex(columnName)));



    this above code works properly for some time. If i keep on clicking the column again and again then it will not wait for the complete post back :( .Here is where i am facing the trouble. I dont know how to handle the ajax request in Watin on click of a button or a link button.I read in few blogs that , "WaitUntil" is helpful in ajax call ... but i am not able to use this for my table column header link button.

    also i tried with myIE.WaitUntilContainsText(columnName); , but here also no hopes :( .Its also not working

    Could anyone please tell me how to handle the ajax calls for a table column header link button in WATIN ? .Thanks in advance for your patience and help :).

    Thanks again


  8.  avatar Pink says:

    Hi all

    I really like WatiN, too. But now i have a problem about write data to exel or read data from exel sheet. Pls help me.



  9.  avatar Junaid says:


    I have been using Watin library in VB.NET an an app to fill some forms online. I wonder if it i spossible to upload a file on a page which is java applet based?


  10.  avatar Jawed says:


    Hi Pink,

    I would like to know that which type of problem r u facing about write data to exel or read data from exel sheet?

    please let me know for that

    or you can dig my blogs for that also



Comments are closed.


Trackbacks and Pingbacks

  1. TrackBack says:
  2. A few days ago I wrote of my initial impressions with WatiN . While I really like it, I mentioned that


Where is Dan?

My Blog
My Blog
Windows Live
Windows Live
Graffiti CMS on CodePlex
Graffiti CMS

Recent Posts