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

19 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. I really like using Gmail but I can't solve my trouble without www.Gmail.com, I think this website are gonna be helpful to you.

    ReplyDelete
  5. 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
  6. 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
  7. Blackbird packaging provide you with any size, shape design, custom bath bomb boxes wholesale sooner than any other packaging competitor in the market

    ReplyDelete
  8. Make your daily life passionately amazing with Guwahati escort and call girl services.
    Romance is not a simple factor that you can bargain with.
    Escorts in Guwahati
    Escort service in Guwahati

    ReplyDelete
  9. Explore the profiles of guwahati escorts, guwahati call girls, call girls in guwahati
    and escorts in guwahati for female companionship in top rated hotels.
    Get affordable escort services in guwahati hotels now.
    College escorts in Guwahati |
    Housewife escorts in Guwahati |
    Assamese call girls in Guwahati |
    Nepali call girls in Guwahati |
    High profile escorts in Guwahati |
    Russian escorts in Guwahati |
    College call girls in Guwahati |
    Call girl service in Guwahati |

    Independent call girls in Guwahati
    Independent escorts in Guwahati

    ReplyDelete
  10. Guwahati Escorts or call girls in Guwahati are those call girl who are rocking and
    amazing in terms of better-quality sexual performance for the customer.
    Guwahati escort
    Guwahati escort service

    ReplyDelete
  11. If you are frustrated in your life and looking for some changes, then it's high time.Make a plan and travel to Guwahati escort
    and choose here Guwahati call girl service. It will remove your tension from life and make your life smooth.
    Assamese call girls in Guwahati
    College escorts in Guwahati
    Housewife escorts in Guwahati
    Nepali escorts in Guwahati
    Escort services in Guwahati

    ReplyDelete
  12. We at Al-Fatah have perfected the floor care with the right variety of Vacuum Cleaners available under one roof. Al-Fatah is a One-Stop Shop for all your home appliances buying needs. Buy best variety of Vacuum Cleaners in Pakistan at Al-Fatah. Shop Vacuum Cleaners of Top & Genuine Brands in Pakistan at Al-Fatah now!

    ReplyDelete
  13. Blackbird packaging provide you with any size, shape design, wholesale cookie boxes sooner than any other packaging competitor in the market

    ReplyDelete
  14. Blackbird packaging provide you with any size, shape design, essential oil packaging boxes sooner than any other packaging competitor in the market

    ReplyDelete
  15. Packaging town is a one stop solution for the short-run custom apparel boxes needs and supplies. At affordable prices. Request a free quote now.

    ReplyDelete
  16. Blackbird packaging provide you with any size, shape design, custom bottle neckers wholesale sooner than any other packaging competitor in the market

    ReplyDelete