为什么Selenium的Internet Explorer驱动程序偶尔无法保持与Web驱动程序服务器的连接?



我为AngularJS网站开发了一些Selenium测试。这些测试使用Chrome驱动程序和Firefox驱动程序运行良好。我正在添加在Internet Explorer驱动程序中运行这些测试的选项。大多数时候,测试也在InternetExplorer中工作,但我已经经历了五次以下异常:

OpenQA.Selenium.WebDriverException:'向远程WebDriver服务器发送URL的HTTP请求时引发了一个具有null响应的异常http://localhost:53472/session/4a73e505-772d-4ef0-beeb-cc15e8b1e647/元件。异常的状态为KeepAliveFailure,消息为:基础连接已关闭:服务器关闭了本应保持活动状态的连接。">

内部异常

WebException:基础连接已关闭:服务器关闭了本应保持活动状态的连接。

第一次出现此异常时,测试已经进行了几分钟;第二次,测试已经运行了3个多小时,接近完成。

可能的相关信息:

  • IE版本:11.778.18362.0

  • 硒版本:3.141.0

  • Selenium IE驱动程序(32位(版本:3.150.1

  • OS Build 18363.778

IEDriver初始化如下:

InternetExplorerOptions options = new InternetExplorerOptions
{
EnsureCleanSession = true,
EnableNativeEvents = true
};
InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
IWebDriver webDriver = new InternetExplorerDriver(driverService, options);

通常导致异常的代码行是:

ICollection<IWebElement> webElementsIncludingDisabled = searchContext
.FindElements(pageElement.By);

其中CCD_ 1是驱动器并且选择器是简单的CsSelector。

堆叠竞赛的相关部分是:

OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:53472/session/4a73e505-772d-4ef0-beeb-cc15e8b1e647/elements. The status of the exception was KeepAliveFailure, and the message was: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElements(String mechanism, String value)

有一次,我的代码中的一行引起了类似的异常:

webElement.SendKeys(toSend);

堆叠竞赛的相关部分是:

OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:50818/session/72b73c2e-d7b2-4e2d-be83-54c343db4109/element/aef8dad2-4c50-41a1-aa36-34957765812a/value. The status of the exception was KeepAliveFailure, and the message was: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
...
This exception was originally thrown at this call stack:
System.Net.Sockets.NetworkStream.Read(byte[], int, int)
Inner Exception 1:
WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Inner Exception 2:
IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
Inner Exception 3:
SocketException: An existing connection was forcibly closed by the remote host

是什么原因导致了这个问题?

有没有一种方法可以影响WebDriver服务器使用的保持活动超时?

这与webDriver.Manage((.Timeouts((.PageLoad超时(当前为默认值(有关吗?


如果我尝试使用64位版本的IEDriver(3.141.59版本(,我会遇到另一个问题:在初始页面加载后,硒似乎总是无法与浏览器通信。在我的代码中实际抛出异常的行是

WebDriver.Url = expectedURL;

不过,通过观察,到目前为止,两次SendKeys和一次Click的尝试都没有成功。

堆叠竞赛的相关部分是:

OpenQA.Selenium.WebDriverException   
HResult=0x80131500   
Message=The HTTP request to the remote WebDriver server for URL http://localhost:55918/session/988d31c6-feb8-4cf0-8335-7c9eaecef6d1/url timed out after 60 seconds.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)    
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) ...
This exception was originally thrown at this call stack:
System.Net.HttpWebRequest.GetResponse() 
OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(OpenQA.Selenium.Remote.HttpCommandExecutor.HttpRequestInfo)
Inner Exception 1: WebException: The request was aborted: The operation has timed out.

我相信这个64位版本的问题与Selenium IE驱动程序在导航到URL 后挂起的问题相同

在一个旧线程中,我发现如果您尝试减少轮询间隔,那么问题就可以解决。

示例:

WebDriverWait myWait = new WebDriverWait(driver, TimeSpan.FromMinutes(5));
myWait.PollingInterval = TimeSpan.FromMilliseconds(500); //I reduced this from checking every 5 second to checking every half second and it started working.
bool waitOnUser = myWait.Until(t =>
{ ...});

参考:

Selenium-异常-连接关闭

你可以尝试的另一件事是减少超时值,看看它是否有助于解决这个问题。

您可以进行测试,并让我们了解您的测试结果。

相关内容

最新更新