find a location for property in a new city

Wednesday 8 June 2011

Why WatiN tests are slow with the IE browser

I found opening and closing of the IE browser in WatiN a massive overhead when I was having to dispose of IE at the end of each of NUnit's tests. I found a way though to speed the whole process up.

I really wanted to open one instance of IE in my NUnit TestFixture and use that for the duration. This would save the huge huge cost of opening and disposing of WatiN's IE browser. As a sidenote it was a lot quicker in FireFox but since most users use IE best stick to that!

There were a couple of hurdles to jump to enable me to use just one IE browser for all my NUnit TestFixture's WatiN tests though.

1. Initialise and Dispose of IE at either end of the TestFixture

This is fairly obvious if you are familiar with NUnit. You just need to utilise the TestFixtureSetUp and TestFixtureTearDown attributes to initialise and dispose of your IE browser like so:
[TestFixture]
public class MyTests : IDisposable
{
    IE Browser;
 
    [TestFixtureSetUp]
    public void Init()
    {
        Browser = new IE();
    }

    [TestFixtureTearDown]
    public void Dispose()
    {
        if (Browser != null)
        {
            Browser.Dispose();
        }
    }

    ...

TestFixtureTearDown will run regardless of any fails in Assertions or even Exceptions so you can be confident that the browser will close on any unmaned CI machines.

2. Solving the weird STA problem (in NUnit)

You need to add to your app.config to ensure the tests run in an single thread apartment (STA) so that the non thread safe Internet Explorer browser can run safely.

I have written separately about how to solve the STA threading problem in Internet Explorer for WatiN.

The overhead of opening and closing the Internet Explorer browser should now be reduced to a one off. I have seen tests times of my NUnit powered WatiN tests reduce from 12 mins down to just 51 secs!

Follow britishdev on Twitter

13 comments:

  1. With nUnit you also have the SetupFixture if you have more than one class.

    ReplyDelete
  2. The overhead of opening and closing the Internet Explorer browser should now be reduced to a one off. heart internet coupons

    ReplyDelete
  3. Motifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium embroidered Lawn, Premium lawn, Premium lawn 2019, Motifz, Premium lawn in Pakistan. Shipping worldwide. Stitching option available.

    ReplyDelete
  4. Buy online wholesale printed candle boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!

    ReplyDelete
  5. Buy online wholesale printed custom candle boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!

    ReplyDelete
  6. Blackbird packaging provide you with any size, shape design, custom bath bomb boxes wholesale sooner than any other packaging competitor in the market

    ReplyDelete
  7. Buy women tracksuits online from ndure at easy prices delivered at your doorstep. Get free shipping

    ReplyDelete
  8. Buy t shirt for men online from Dshred at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  9. Buy toys online from Al-Fatah at best prices delivered at your doorstep. Get free shipping

    ReplyDelete
  10. Buy online toys in Pakistan from Al-Fatah at best prices delivered at your doorstep. Get free shipping.

    ReplyDelete
  11. Your blogs are amazing. Keep sharing. I love them Are you also searching for coursework help? we are the best solution for you. We are best known for delivering the best urgent assignment help.

    ReplyDelete
  12. Nice blog, I loved to read all your blog keep sharing.
    www.aaafencedeck.com

    ReplyDelete