1

I have a number of tests that seem to be randomly failing due to a Timeout while Internet Explorer busy error.

WatiN.Core.Exceptions.TimeoutException: Timeout while Internet Explorer busy

They errors seem to be only caused on lines with code of:

WatiN.Core.Browser.AttachTo[T](Constraint constraint)

My setup method:

[SetUp]
[Timeout(1000)]
public void WithAnInstanceOfTheBrowser()
{
    Settings.AttachToBrowserTimeOut = 200;
    Settings.WaitUntilExistsTimeOut = 200;
    Settings.WaitForCompleteTimeOut = 200;
    Settings.SleepTime = 60;

    BrowserExtension.KillAllIEProcess();

    var securePassword = new SecureString();
    foreach (var c in UserConfig.GetConfigPassword())
    {
        securePassword.AppendChar(c);
    }

    string address = UserConfig.GetConfigUrl();
    string username = UserConfig.GetConfigUserName();
    ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Program Files\Internet Explorer\iexplore.exe", address);
    startInfo.UserName = username;
    startInfo.Password = securePassword;
    startInfo.UseShellExecute = false;
    startInfo.LoadUserProfile = true;
    Process.Start(startInfo);
    _browser = Browser.AttachTo<IE>(Find.ByUrl(UserConfig.GetConfigUrl()));
}

_browser is a global variable at the class level:

IE _browser;

Then in the test I perform a number of actions on the window that opens up and one of these actions is clicking a button and this button opens a new tab within the application. Then to get a reference to this new page I use the lines:

Thread.Sleep(6000); //even sleeping but to no avail
Browser workItem = Browser.AttachTo<IE>(Find.ByTitle(new Regex(workItemRegex)));

This seems to throw back errors randomly, Sometimes it works and sometimes I get an error.

I'm not exactly sure whats going wrong here because it seems logical that this should work.

In the TearDown of the test all IE processes are killed and _browser is set to null.

Any Ideas?

Ben
  • 2,518
  • 4
  • 18
  • 31

1 Answers1

0

I've seen this before and it happened to me while trying to close and re-open IE and then re-attaching to the browser. But while I can't find a logic explanation to why it fails I did find out why it was timing out on me (at least in my case) and it is because even when you kill the IE object before instantiating a new one the shutdown of IE takes longer than expected (believe me I've tried several minutes) so the only solution for me was to just kill the process I was using before creating a new one and from that moment on I haven't had any issues. Hope this helps your situation.

ProgrammerV5
  • 1,915
  • 2
  • 12
  • 22
  • I've combated this issue by for one using a combination of AttachToNoWait and Thread.Sleep(XXXX). I've also tried to structure my tests different in that I pass the current window I am working on to helper methods instead of creating a reference to the specific page as part of the helper methods. I will accept your answer as in my experience this is exactly what causes the problem. These are just some work arounds I have used. – Ben Sep 22 '15 at 11:11
  • I've been there before and I've used one instance and move it around in between classes but I've also found situations were there is no alternative but to run another instance and attach to it, then kill that instance and re-instatiate and in this case killing the process works great. – ProgrammerV5 Sep 22 '15 at 17:47