向远程WebDriver服务器发送的针对URL的HTTP请求...在60秒后超时

时间:2019-02-04 18:55:53

标签: selenium selenium-iedriver

我正在将Selenium与Internet Explorer Web驱动程序(IEDriverServer)一起使用。由于某种原因,我找不到用于在此打开此错误的代码库。因此,如果有人也能指出我的方向,我将不胜感激。

此问题似乎已在所有驱动程序中广泛传播,这表明硒的基本问题。但硒有already denied是他们的问题。当前,人们似乎已经使用各种各样的黑客技术来克服持续存在的问题。

一个人here on SO似乎也有类似的问题,并建议通过增加超时来解决该问题,这对我来说似乎是一个可怕的主意,因为这只会减慢我的整体测试速度。

我遇到了以下例外情况:

  

消息:到远程WebDriver服务器的URL的HTTP请求   http://localhost:24478/session/07896235-84ea-465e-a361-cb0ef5885ef2/url   60秒后超时。 StackTrace:位于   OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo   requestInfo)   OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command   commandToExecute)   OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command   commandToExecute)   OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串   driverCommandToExecute,Dictionary的2个参数)位于   OpenQA.Selenium.Remote.RemoteWebDriver.get_Url()

  

消息:到远程WebDriver服务器的URL的HTTP请求   http://localhost:24478/session/07896235-84ea-465e-a361-cb0ef5885ef2/window/rect   60秒后超时。 StackTrace:位于   OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo   requestInfo)   OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command   commandToExecute)   OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command   commandToExecute)   OpenQA.Selenium.Remote.RemoteWebDriver.Execute(字符串   driverCommandToExecute,Dictionary的2个参数)位于   OpenQA.Selenium.Remote.RemoteWindow.get_Position()

我是通过几个不同的随机调用来获取此信息的。就像当我尝试获取浏览器的当前网址,或当我尝试单击浏览器中的元素时一样。

到目前为止,在我目前的测试中,看来我的测试能够恢复自身并继续进行下去,因此仍会采取进一步的措施。我将尝试尝试一些技巧,但是实施和测试它们需要几天时间,从而使问题更加随机。

我正在使用Nuget Selenium.WebDriver软件包v3.141.0 IEDriverServer v3.8。由于驱动程序的另一个已知问题,我从v3.9回滚。

有人知道此问题的修复程序,或没有此问题的IE驱动程序版本吗?

这是我第一次推出Selenium。到目前为止,我已经使用CodedUI,并且效果很好,但是自从Microsoft宣布停止使用它以来,我一直在尝试将Selenium产品作为替代产品上线。到目前为止,我已经克服了大多数Selenium的不足,可以给我自己类似CodedUI的功能,希望这是剩下的最后一个问题。

这是我启动驱动程序的基本电话:

        /*
         * Startup the correct Selenium browser driver.
         */
        _Service = InternetExplorerDriverService.CreateDefaultService(seleniumPath);

        var options = new InternetExplorerOptions()
        {
            // Mouse clicking takes a long time using NativeEvents, so trying turning it off
            EnableNativeEvents = false
        };
        _Browser = new InternetExplorerDriver((InternetExplorerDriverService)_Service, options);

        _Browser.Manage().Timeouts().PageLoad = new TimeSpan(0, 5, 0); // wait for 5 minutes

1 个答案:

答案 0 :(得分:1)

我创建了一些通用的重试方法。这是围绕硒限制的一种破解。 Selenium具有一些内置的超时,可以并且应该在适当的地方使用它,但是并非所有对驱动程序的调用似乎都可以接受这些超时。同样,并非所有的驾驶员通信问题都归因于Selenium在没有听到回音后超时。如果问题是由于网络或权限问题引起的,那么这些方法将根本无济于事。

应该使用Selenium中针对PageLoad,Script和ImplicitWait的主要超时来解决特定于这些区域的超时问题。

这些方法(从另一个来源进行了修改)解决了一组非常狭窄的问题,即Selenium在调用过程中或超时时失去与Web驱动程序的连接,而您无法延长超时时间。它们通过启动对驱动程序的新调用来工作,在某些情况下,这可能导致该操作在浏览器中被多次调用,因此请谨慎使用它们。

    /// <summary>
    /// These retry methods are necessary because Selenium is incapable of handling timeouts
    /// inside it's own system when it temporarily loses connection to the Driver.
    /// Called like:
    /// var return = RetryWebDriverServiceCall(f => object.method(param));
    /// var return = RetryWebDriverServiceCall(f => object.attribute);
    /// </summary>
    /// <param name="serviceMethod"></param>
    public delegate void VoidAction(params object[] oArgs);
    public void RetryWebDriverServiceCall(VoidAction serviceMethod)
    {
        for (var loop = 0; loop < 3; loop++)
        {
            try
            {
                serviceMethod();
                break;
            }
            catch (WebDriverException ex) //  (WebDriverTimeoutException ex)
            {
                if (!ex.Message.Contains("timed out after 60 seconds") || loop >= 2)
                    throw new Exception($"UI Retry #: {loop}", ex);
                System.Threading.Thread.Sleep(500);
            }
        }
    }

    public delegate T ParamsAction<T>(params object[] oArgs);
    public T RetryWebDriverServiceCall<T>(ParamsAction<T> serviceMethod)
    {
        for (var loop = 0; loop < 3; loop++)
        {
            try
            {
                return serviceMethod();
            }
            catch (WebDriverException ex)
            {
                if (!ex.Message.Contains("timed out after 60 seconds") || loop >= 2)
                    throw new Exception($"UI Retry #: {loop}", ex);
            }
        }

        throw new Exception("RetryWebDriverServiceCall failed");
    }