Browser.AttachTo 时 Internet Explorer 忙时超时错误

Timeout while Internet Explorer busy error when Browser.AttachTo

我有一些测试似乎由于 Internet Explorer 忙时超时错误而随机失败。

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

他们的错误似乎只在代码为:

的行上引起

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

我的设置方法:

[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是class级别的全局变量:

IE _browser;

然后在测试中,我对打开的 window 执行了一些操作,其中一个操作是单击一个按钮,此按钮将在应用程序中打开一个新选项卡。 然后为了获得对这个新页面的引用,我使用以下行:

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

这似乎随机抛出错误,有时有效,有时我会出错。

我不确定这里出了什么问题,因为这似乎符合逻辑。

在测试的 TearDown 中,所有 IE 进程都被杀死,_browser 设置为 null。

有什么想法吗?

我以前见过这种情况,它发生在我尝试关闭并重新打开 IE,然后重新连接到浏览器时。但是,虽然我找不到它失败原因的逻辑解释,但我确实找到了它超时的原因(至少在我的情况下),这是因为即使你在实例化一个新的 IE 对象之前杀死了 IE 对象,关闭IE 花费的时间比预期的要长(相信我,我已经尝试了几分钟)所以对我来说唯一的解决方案是在创建新进程之前终止我正在使用的进程,从那一刻起我就没有遇到任何问题。希望这对您的情况有所帮助。