Digging My Blog - Dan Hounshell

Another .Dan Powered Site

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:

    [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");
        }
    }

  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.


Comments

TrackBack said:

# March 8, 2007 6:46 AM

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.

# March 9, 2007 1:52 PM

Dan Hounshell said:

Thanks for the info, Alex.

# March 9, 2007 2:21 PM

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

# March 11, 2007 2:21 PM

Dan Hounshell 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.

# March 11, 2007 6:05 PM

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

# March 12, 2007 3:27 PM

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 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...

# November 9, 2007 3:46 AM

Dan Hounshell said:

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

http://danhounshell.com/blogs/dan/archive/2007/03/12/an-update-to-my-watin-experience.aspx

Thanks,

Dan

# November 9, 2007 5:09 AM

rüya tabiri said:

thank You.

# November 25, 2008 3:12 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Please type in: hello world