WatiN Dispose() is really slow
Asked Answered
M

3

12

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?

Mabellemable answered 3/8, 2009 at 18:22 Comment(2)
I know this is old, but is anyone else experiencing similar issues?Vocalize
Could you post a representative sample of the Watin functions that you're calling along with their frequency?Kuebbing
N
1

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.

Nowise answered 28/2, 2012 at 21:40 Comment(1)
This is the only method that has resolved the slow close for me.Petrinapetrine
B
0

I've been having the same, intermittent problem with IE9. My colleagues either side of me do not have the same issues. We have just realised that my default browser is IE and I tend to have it open with several tabs running.

I've been working with no IE open on the desktop while my WatIn tests run and I haven't had the problem since I adopted this practice.

Possibly coincidence, or possibly the answer?!

Beria answered 3/11, 2011 at 10:0 Comment(0)
A
0

What you need to do is set the thread the test is running on into STA mode, and IE will close quickly.

 [CodedUITest]
 public class DoSomeAutomatedTesting
 {
     public DoSomeAutomatedTesting()
     {
         // Hey! Hey! Hey! We can't do no MTA!
         Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
     }

     [TestMethod]
     public void MyTestMethod()
     {
         using(var ie = new IE())
         {
             ie.AutoClose = true;
             ie.GoTo("http://www.google.com");
         }     
    }
}

For those of you who aren't old farts who have done COM programming, this describes an STA http://msdn.microsoft.com/en-us/library/windows/desktop/ms680112(v=vs.85).aspx. Short story, STA is an old-school technique used by COM to preserve the viability of existing, tested, working, single-threaded code left over from the Windows 95 days in the scary, new-fangled world of preemptive multithreading.

Now, the CLR lives in what the COM calls the MTA. For those of us that don't live in 1998, you can think of the MTA as the real world, where things work the way they should. http://msdn.microsoft.com/en-us/library/windows/desktop/ms693421(v=vs.85).aspx

When some thread in the super-scary MTA wants to access something in an STA, the MTA thread is told to sit on the bench and wait its turn if the STA is currently being accessed by a different thread from the MTA. This basically means that sometimes, when the weather isn't right, you can get these wierd-o lags.

Anjanetteanjela answered 6/8, 2013 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.