Category Archives


Modal dialog’s and dropdowns in Watin

Although I don’t yet have time to start using WATIN full time at work, I managed to convert a few more tests over to compare how the tests work. I am doing this in my spare time (i.e lunch and after work), to building A proof of concept and see how the framework will go in real world testing situations. For this post I have removed all references to our real application and mocked up a sample application.

The part of our app that I have simulated has a model dialog, a group of drop down’s in that each refresh when the one above it changes, and an image button implemented on an ‘input’ tag to launch the dialog. The sample dialog looks like this mock-up.

The test case was a very simple one, click the image, select a value in each of the drop-down’s, click OK then validate the page contains some text. There were a few interesting challenges, but nothing that I couldn’t solve by adding some code to the Watin framework and recompiling. Here is an altered version of the resultant code.

 public void AddNewUser()
    using (IE ie = new IE(baseURL))
        // Click on the 'Manage customers' button to open the customer
        // management screen

    // Click on the add customer image button (an INPUT tag with type image)
    // We need to use ClickNoWait as the Create customer dialog is a modal dialog
    // and the readystate does not return to complete until the dialog is closed.

    // Find the new 'Create new customer' dialog that opens in the collection
    // of dialogs and wait a maximum of 2 seconds for the dialog
    HtmlDialog dialog = ie.HtmlDialog(Find.ByTitle("Select ticket type"),2);

    // Select Melbourne, Qantas and Business class
    // We need the thread.sleep as these contols load dynamically based on
    // the previous selection and we are in dialog mode
    dialog.MainDocument.SelectList(Find.ById(ddlCustomerAirline_Id)).Select("Qantas") ;


    // Test that the text 'Melboune' is in the page

    // Test that the text 'Qantas' is in the page

    // Test that the text 'Business class' is in the page
    Assert.IsTrue(ie.MainDocument.ContainsText("Business class"));

So what were the traps?

Internet Explorer implements a ReadyState property which indicates that the browser is loading, rendering the page, etc. ReadyState typically returns an enum value of READYSTATE_COMPLETE when the browser is loaded and ready for more input. Where the challenge comes in is that his behaviour changes when when a modal dialogue is shown The browser does not return READYSTATE_COMPLETE, yet it is waiting for user input. To work around this issue Watin implements a ClickNoWait() method to use instead of the Click() method under these circumstances.

The problem I ran into (apart from an un-handled exception being thrown from the click method) was that the applicaiton dynamically loads the value of one dropdown after a value is selected in the one above it. This required a Thread.Sleep call to pause the script for 2 seconds, after each drop-down list is selected. I don't think that this solution is very elegant, and it adds some 6 additional seconds to the execution time for this test. This definitely warrants some further investigation into what the IE ReadyState is when the dialog is shown, writing another wait method for the Watin ie object, that waits for that state to change.

Anyway so far Watin is meeting my expectations and still looks like it will be able to handle just about everything I can throw at it.

Testing Watin3 comments

The holy grail: .net automated web GUI testing for internet explorer

If you are looking (as I have been for a while) for a solution on how to write automated web GUI tests for internet explorer in .net then look no further. WATIR has been ported to C# as the WATIN framework. I have compiled the framework in .net 2.0 with minimal fuss, and it feels like it should have shipped out of the box with Visual Studio Team Edition for Software Testers.

So is it any good? I have spent about 2 hours so far converting one of my simple tests across, and this thing rocks. The tests are simple and execute very quickly. The following sample, copied from the WATIN homepage, searches for this site in google and checks for the text “Saving the world, one test case at a time” in the browser window.

    public void Google()
      using (IE ie = new IE(""))

    Assert.IsTrue(ie.MainDocument.ContainsText("test case"));

The best part of all, is that if you use NUnit and Visual C# Express Edition, your total cost is $0.

Testing Watin3 comments

1 3 4 5 6 7