Belizzle
Belizzle

Reputation: 1414

Sporadic Selenium Chrome WebDriver timeouts starting with chrome 85

I have a few .NET Core automation projects using Selenium and running against Chrome. The builds are running in a Jenkins pipeline, currently running the tests on a Linux build agent.

These tests all ran perfectly when we were running against chrome 83, but when we had our dev ops team upgrade to chrome 85 we started seeing sporadic timeouts. When the timeouts occur we see the following error for each test:

Error Message:
OneTimeSetUp: OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:41307/session/008798b4a2c52b867ec157b20d89f9b9/url timed out after 60 seconds.
    ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
    ----> System.IO.IOException : Unable to read data from the transport connection: Operation canceled.
    ----> System.Net.Sockets.SocketException : Operation canceled

This timeout is not isolated to a single test, but if it happens, the same error message will appear for every test in the test run.

This happens, on average, every 2-3 times the tests run. It is not a question of timing as sometimes scheduled runs succeed and other times fail, and I can run the tests over and over, back to back, and will get successes and failures randomly intermixed.

What I have tried so far:

It is also worth noting that we have not seen this happen a single time running locally through Visual Studio. It is only when executing these tests through our Jenkins pipeline that we see this behavior.

Any ideas on how to resolve these random timeout failures?

edit:

Adding the code I am using to initialize the chromedriver:

var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("--no-sandbox", "--start-maximized");
chromeOptions.AddArguments("--window-size=1920,1080", "--headless"); // Comment out if running locally to see execution
chromeOptions.AddUserProfilePreference("safebrowsing.enabled", "true");
WebDriver = new ChromeDriver(chromeOptions);

The server we are running against is headless but I left the start-maximized flag in place for easier local debugging.

edit 2:

This is the rest of the code executed within the OneTimeSetUp method which utilizes the webDriver:

public LoginService(IWebDriver webDriver)
{
    _webDriver = webDriver;
}

public void OpenAndLoginToApplication(string applicationUrl, string username, string password)
{
    _webDriver.Navigate().GoToUrl(string.Format(LoginPageUrlTemplate, applicationUrl));

    _webDriver.SetInputFieldValue(By.Id(UsernameFieldId), InputFieldType.Text, username);
    _webDriver.SetInputFieldValue(By.Id(PasswordFieldId), InputFieldType.Text, password);

    _webDriver.ClickAndConfirmByElementVisibility(By.Id(LoginButtonId), By.Id(LoggedInUserDropdownId));
}

Upvotes: 0

Views: 1280

Answers (1)

Belizzle
Belizzle

Reputation: 1414

I was never able to figure out why this was happening, but I was able to solve this problem.

I found that the timeout was happening on Navigate() to the application. No matter how much I increased the timeout, I would still get the failure. However, a subsequent Navigate() call would succeed.

So my solution to this was to simply retry navigating to the application url if we receive a WebDriverException (the timeout exception) on the initial call.

Upvotes: 1

Related Questions