【问题标题】:HTTP request to the remote WebDriver server for URL timeout when running tests across browsers in parallel跨浏览器并行运行测试时对远程 WebDriver 服务器的 HTTP 请求以获取 URL 超时
【发布时间】:2017-12-07 12:23:45
【问题描述】:

几个月来,我一直在与常见的“对远程 WebDriver 服务器的 URL 的 HTTP 请求......在 x 秒后超时”作斗争,试图同时对两个浏览器(Chrome 和 IE)运行测试,花费一次几个小时在 stackoverflow 和搜索引擎结果中寻找解决方案。

与我之前的其他人一样,我的行为在点击功能超时或尝试获取 url 时有所不同,并且在各种情况下,我已将页面加载和隐式等待超时增加到 600 秒以上,在元素之前插入等待,调用url之后,调用url之前,调用驱动构造函数之后,作为驱动对象调用中的参数。

我已尝试包含 javascript 执行器脚本(由之前关于此问题的 SO 帖子中的答案提供),在继续操作之前检查页面加载就绪状态是否已完成,但未成功。

我已尝试将我的 chrome 和 IE、selenium web 和支持驱动程序都更新到最新的兼容版本,手动调用二进制文件以获取最新的兼容浏览器可执行文件 - 以及尝试回滚到人们报告的先前版本成功(chrome v48、chromedriver 2.22.0.0、webdriver 2.53.1)。我尝试将“no-sandbox”添加为 chrome 选项,确保我的 IE 安全区域都共享相同级别的保护。

我调查了我的页面是否使用 AJAX 脚本,并尝试使用各种线程中提供的解决方案来适应任何动态内容。

在并行查询之外单独运行 IE 或 Chrome 时,不会观察到超时问题。当 chrome 初始化其远程 WebDriver 实例时,会特别出现此问题。我也尝试过使用 32 位和 64 位版本的 chrome/ie 驱动程序。

我从许多主题和页面中提取了信息,但这些都是最相关的。

Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds

https://sqa.stackexchange.com/questions/13326/the-http-request-to-the-remote-webdriver-server-timed-out-after-60-seconds

https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5441

https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5071

Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds

Selenium WebDriver throws Timeout exceptions sporadically

这是一个输出示例:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.AggregateException : One or more errors occurred.
  ----> OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:52240/session/a969dbe2-3b0c-461f-a979-21bafec0dd8e/element/7005aeab-ff31-454a-8f78-0a39ad861695/click timed out after 120 seconds.
  ----> System.Net.WebException : The request was aborted: The operation has timed out.

我从后来添加到并行查询的案例列表中调用驱动程序:

 private static IWebDriver DefineDriver(Browser supportedbrowsers)
        {
            var baseDriverPath = ConfigurationManager.AppSettings["BaseDriverPath"].ToString();
            var ieDriverFolder = ConfigurationManager.AppSettings["IeDriverFolder"].ToString();
            var chromeDriverFolder = ConfigurationManager.AppSettings["ChromeDriverFolder"].ToString();
            ChromeOptions chromeoptions = new ChromeOptions();
            chromeoptions.BinaryLocation = @"C:\WebDrivers\Binary\chrome32_49.0.2623.75\chrome.exe";
            chromeoptions.AddArgument("no-sandbox");
            InternetExplorerOptions ieoptions = new InternetExplorerOptions();
            ieoptions.IntroduceInstabilityByIgnoringProtectedModeSettings = false;


            IWebDriver driver = null;
            switch (supportedbrowsers)
            {
                case Browser.Chrome:
                    driver = new ChromeDriver(Path.Combine(baseDriverPath, chromeDriverFolder), chromeoptions, TimeSpan.FromMinutes(5));
                    break;
                case Browser.InternetExplorer:                
                    driver = new InternetExplorerDriver(Path.Combine(baseDriverPath, ieDriverFolder), ieoptions, TimeSpan.FromMinutes(5));
                    break;
                default:
                    driver = new ChromeDriver(Path.Combine(baseDriverPath, chromeDriverFolder), chromeoptions, TimeSpan.FromMinutes(5));
                    break;
            }

            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(120));
            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMinutes(10));
            driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMinutes(10));

            driver.Manage().Window.Maximize();

            return driver;
        }

在我的测试代码中,我只是启动一个页面,导航到另一个本地页面,然后尝试单击页面上立即可见的按钮。

我尝试将按钮的单击命令包装在 try catch 中,添加了具有预期条件的显式等待(显示、启用、可单击),使用的线程睡眠在运行单个浏览器时都按预期工作。

例如,我通过以下方式调用按钮:

 public void SelectAddWorkWorkPageButton()
    {
        WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
        wait.Until(ExpectedConditions.ElementToBeClickable(addNewWorkItemWorkPageBtn));
        addNewWorkItemWorkPageBtn.Click();
    }

其中定位以下元素:

//Create New Button
        [FindsBy(How = How.Id, Using = "btnWorkDefinitionCreateNewWorkDefinition")]
        public IWebElement addNewWorkItemWorkPageBtn { get; set; }

它是 HTML:

<i id="btnWorkDefinitionCreateNewWorkDefinition" title="Add work" class="fa fa-plus-circle cursorPointer crudIcon" style="font-size: 20px;margin:0;padding-left:15px" ng-click="AddNewWorkDefinition()" role="button" tabindex="0"></i>

作为关于超时的单独说明,在更新到最新版本的 WebDriver 时,我还将超时更新为新格式:

    //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(120);
    //driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
    //driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(120);

这个问题似乎早在 2012 年就已经存在于社区中,据我发现,从未被孤立和明确地发现过,今年 5 月仍有人报告它。

Selenium Error - The HTTP request to the remote WebDriver timed out after 60 seconds

【问题讨论】:

    标签: c# selenium selenium-chromedriver selenium-iedriver


    【解决方案1】:

    在尝试了更多解决方法(包括使用量角器来解释 AngularJS 代码)之后,我终于将“对远程 WebDriver 服务器的 HTTP 请求以获取 URL”异常消息的原因隔离到运行时的特定问题IEDriver 单独或与测试中的应用程序并行。

    应用程序似乎正在使用 SignalR 连接来处理某些进程,这导致 IEDriver 操作(例如单击事件)超时,因为 SignalR 连接永远不会完成,因此导致 IEDriver 无法确定页面在执行其他操作之前已完成加载。

    当 SignalR 连接类型更新为使用“长轮询”时,这完全解决了 IEDriver 超时问题。

    这些帖子中提供了更好的解释,并且很多功劳归功于那些在其中做出贡献的人,否则我永远不会猜到 SignalR 是原因: https://github.com/SignalR/SignalR/issues/293

    SignalR w/ Web Sockets

    C# Protractor AngularJS IEDriverServer Click() Exception "Timed out waiting for page to load"

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      • 2018-03-22
      • 1970-01-01
      相关资源
      最近更新 更多