all posts

I really like WatiN

Published to Blog on 5 Mar 2007

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:

[Test]
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";
    ie.Button("btnLogin").Click();
    //Should be redirected back to the home page, check for expected text
    Assert.IsTrue(ie.ContainsText("Expected text"), "Unsucessful login");
  }
}
  1. 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.


Dan Hounshell
Web geek, nerd, amateur maker. Likes: apis, node, motorcycles, sports, chickens, watches, food, Nashville, Savannah, Cincinnati and family.
Dan Hounshell on Twitter


  • On 8 Mar 2007 "TrackBack"" said:
  • On 9 Mar 2007 "Alex"" said:
    You can also check SWExplorerAutomation SWEA from http//webiussoft.com. 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.
  • On 9 Mar 2007 """ said:
    Thanks for the info, Alex.
  • On 11 Mar 2007 "Jeroen van Menen"" said:
    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
  • On 11 Mar 2007 """ said:
    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, Dan.
  • On 12 Mar 2007 "Digging My Blog - Dan Hounshell"" said:
    A few days ago I wrote of my initial impressions with WatiN . While I really like it, I mentioned that
  • On 8 Nov 2007 "Matthew Evans"" said:
    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 expiresI 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...
  • On 9 Nov 2007 """ said:
    Matthew, I explained in a followup post what I did that corrected the issue /blog/an-update-to-my-watin-experience/ Thanks, Dan
  • On 24 Nov 2008 "r&252;ya tabiri"" said:
    thank You.
  • On 15 May 2009 "Keshav"" said:
    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))); myLink.ClickNoWait(); myLink.WaitForComplete(); then didnt work. Again i tried with Link myLink = table.Link(Find.ByText(new Regex(columnName))); myLink.ClickNoWait(); System.Threading.Thread.Sleep(3000); 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 Keshav
  • On 24 Jul 2009 "Pink"" said:
    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. Thanks Pink
  • On 29 Jul 2009 "Junaid"" said:
    Hi, 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? Thanks.
  • On 22 Sep 2009 "Jawed"" said:
    @Pink 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 jawed.ace@gmail.com or you can dig my blogs for that also http//jawedm.blogspot.com Thanks, Md.Jawed