Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WatiN Dispose() is really slow

My WatiN tests have suddenly gotten REALLY slow when I dispose the Internet Explorer object.

Here's my setup...

* Windows 7 (Evaluation Build 7100)
* Internet Explorer 8 (Version 8.0.7100.0)
* WatiN (Version 2.0.10.928)

This is strange because the tests were working fine a week or so ago. I think it's the latest MS Updates or something.

Any ideas?

like image 869
Garth Avatar asked Aug 03 '09 18:08

Garth


1 Answers

I was having issues with IE closing slowly (or never), but after doing the following I've had zero issues:

My setup:
*IE 9
*Windows 7
*Watin 2.1
*Visual Studio 10 SP1, using Microsoft.VisualStudio.TestTools.UnitTesting
  1. Rather than a pattern like those described in Mikecito's links, I use a version of the BrowserStaticInstanceHelper described by Jeroen van Menen, Watin hero, here. It provides a way to zero in and attach to a specific browser window.
  2. Using this strategy has the bonus of only starting up one IE for multiple test methods and multiple test classes. AND, when all tests finish, IE closes within 1 or 2 seconds.

One last issue:

Since I have multiple TestMethods and TestClasses, I wanted to put IE.Close() in an AssemblyCleanup() method. Due to MSTest threading issues, I then had to call close() like this:

[AssemblyCleanup()]
public static void CleanupAllTests()
{
    var thread = new Thread(() =>
    {
        IE.Close();
    });
    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();
}

*Again, IE in this snippet refers to a property that will check for and attach to my IE instance using the strategy from the link above. This snippet probably won't solve your problems without the rest of the pattern that I linked to.

Before this setup IE would sometimes take 30+ seconds to close, now I can open and close other IE windows all I want while the tests are running, and the browser always closes reliably.

like image 110
gregshap Avatar answered Oct 14 '22 22:10

gregshap