HTTP request to the remote WebDriver server for URL timeout when running tests across browsers in parallel

Brad Naus picture Brad Naus · Jul 4, 2017 · Viewed 7.2k times · Source

I've been battling the commonly seen "HTTP request to the remote WebDriver server for URL ... timed out after x seconds" for several months in an attempt to run tests against two browsers simultaneously (Chrome and IE), spending hours at a time trawling through stackoverflow and search engine results to attempt to find a solution.

My behavior, like others before me, varies between timing out at a click function or when attempting to get a url, and I have increased pageload and implicit wait timeouts to over 600 seconds in various cases, inserting the waits before an element, after a url is called, before a url is called, after the driver constructor is called and as a parameter in the driver object call.

I have attempted to include javascript exectutor scripts (provided from answers in previous SO posts on this issue) that check for the page load ready state to be complete before continuing with an action, to no success.

I have attempted to update my chrome and IE, selenium web and support drivers all to the latest compatible versions, manually calling the binary for the latest compatible browser executable - as well as attempting to roll back to previous versions where people have reported success (chrome v48, chromedriver 2.22.0.0, webdriver 2.53.1). I've tried adding "no-sandbox" as a chrome option, ensured that my IE security zones all shared the same level of protection.

I've investigated whether my page is using AJAX scripts and attempted to use the solutions provided in various threads to accommodate for any dynamic content.

When running either IE or Chrome individually, outside of the parallel query, no timeout issues are observed. The issue specifically occurs when chrome initializes its remote WebDriver instance. I've also tried using 32bit and 64bit versions of the chrome/ie drivers.

I've pulled information out of many topics, and pages, but these are some of the most relevant ones.

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

Here's an example of the output:

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.

I call the drivers from a case list where there are later added in to the parallel query:

 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;
        }

In my test code, I am simply launching a page, navigating to another local page and then attempting to click a button that is immediately visible on the page.

I've tried wrapping the click command for the button in a try catch, added explicit waits with expected conditions (displayed, enabled, isclickable), used thread sleep which have all worked as expected when running a single browser.

For example, I call the button via:

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

Which locates the following element:

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

And it's 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>

As a separate note regarding the timeouts, when updating to the latest versions of the WebDriver, I have also updated the timeouts to their new format:

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

This issue seems to have existed in the community since as far back as 2012 and has, to my finding, never been isolated and clearly identified, with people still reporting it in May this year.

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

Answer

Brad Naus picture Brad Naus · Sep 1, 2017

After attempting several more workarounds, including the use of Protractor to account for AngularJS code, I've finally isolated the cause of the "The HTTP request to the remote WebDriver server for URL" exception message down to a specific issue when running the IEDriver individually or in parallel against the application in test.

It appears that the application was using a SignalR connection to handle certain processes and this causing the IEDriver actions (such as a click event) to timeout because the SignalR connection would never complete and therefore result in the IEDriver not being able to determine that the page had finished loading before it could perform another action.

When the SignalR connection type was updated to use "Long Polling" this resolved the IEDriver timeout issue entirely.

Better explanations are available in these posts, and much credit is owed to those who contributed within, I'd never have guessed that SignalR was the cause otherwise: https://github.com/SignalR/SignalR/issues/293

SignalR w/ Web Sockets

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

Thanks.