Browser.AttachTo <T>()导致间歇性异常"Internet Explorer忙时超时"

Cra*_*lla 10 .net watin timeout internet-explorer-9

作为持续集成构建过程的一部分运行的WatiN步骤在尝试间歇性地附加到浏览器实例时失败.目前约有五分之一.

Browser.AttachTo<IE>(Find.ByTitle("Title of Popup"));
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

WatiN.Core.Exceptions.TimeoutException: Timeout while Internet Explorer busy
   at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.ThrowTimeOutException(Exception lastException, String message)
   at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.HandleTimeOut()
   at WatiN.Core.UtilityClasses.TryFuncUntilTimeOut.Try[T](DoFunc`1 func)
   at WatiN.Core.WaitForCompleteBase.WaitUntil(DoFunc`1 waitWhile, BuildTimeOutExceptionMessage exceptionMessage)
   at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitUntilNotNull(DoFunc`1 func, BuildTimeOutExceptionMessage exceptionMessage)
   at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitWhileIEBusy(IWebBrowser2 ie)
   at WatiN.Core.Native.InternetExplorer.IEWaitForComplete.WaitForCompleteOrTimeout()
   at WatiN.Core.WaitForCompleteBase.DoWait()
   at WatiN.Core.Native.InternetExplorer.AttachToIeHelper.FinishInitializationAndWaitForComplete(IE ie, SimpleTimer timer, Boolean waitForComplete)
   at WatiN.Core.Native.InternetExplorer.AttachToIeHelper.Find(Constraint findBy, Int32 timeout, Boolean waitForComplete)
   at WatiN.Core.Browser.AttachTo[T](Constraint constraint)
Run Code Online (Sandbox Code Playgroud)

我已经完成了以前帖子中建议的所有显而易见的事情:

即在运行WatiN步骤之前杀死所有Internet Explorer进程:

Process.GetProcessesByName("IEXPLORE").ToList().ForEach(p => p.Kill());
Run Code Online (Sandbox Code Playgroud)

在运行任何WatiN步骤之前增加超时:

var timeout = 60;
Settings.AttachToBrowserTimeOut = timeout;
Settings.WaitForCompleteTimeOut = timeout;
Settings.WaitUntilExistsTimeOut = timeout;
Run Code Online (Sandbox Code Playgroud)

每个WatiN步骤都作为以下代码块中的操作传入:

public void UseAndCloseBrowser(Action<Browser> action, Browser browser)
{
    try
    {
        action(browser);
        browser.WaitForComplete();
    }
    finally
    {
        Log(Level.Info, "Attempting to close browser {0}", browser.Title);
        browser.Close();
        browser.Dispose();
    }

}
Run Code Online (Sandbox Code Playgroud)

有没有人知道我能做的其他事情/检查这个恼人的错误信息的底部?

Nat*_*nSr 1

我过去也遇到过类似的问题,解决方案是简单地在每个会话中重复使用相同的浏览器窗口。在执行第一个测试时创建一个浏览器窗口并将其用于所有测试,然后可以选择在测试会话结束时将其关闭。显然,这取决于您使用的测试工具,但它应该可以工作。创建和销毁 IE 窗口是一项资源密集型活动,因此最好尽可能避免这样做。