Search code examples
c#.netwatinmbunit

Timeout while Internet Explorer busy error when Browser.AttachTo


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?


Solution

  • 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.