Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver throws Timeout exceptions sporadically

Using selenium for ui tests on our project. We are running the newest version 2.30.0. We use Firefox WebDriver and are running Firefox 19.0.

Generally said the ui test works local and even server side when I run the ui test in Visual Studio. Our ui tests gets executed nighlty on our build server. It uses the same deploy on the same server I test manually via Visual Studio.

But sporadically we run into following issue when the ui test gets executed on buildserver:

Test(s) failed. OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:7056/hub/session/bed1d0e7-efdc-46b6-ba07-34903519c44d/element/%7B8717bb19-96c7-44d3-b0ee-d4b989ae652d%7D/click timed out after 60 seconds.       ----> System.Net.WebException : The operation has timed out        at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)        at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) --WebException    at System.Net.HttpWebRequest.GetResponse()    at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) 

Basically the test clicks on an upload button where the input field was filled with a file before. Since the file is very small this gets done in a few seconds. Nevertheless the timout of 60 seconds is reached sometimes.

Any ideas how to isolate the underlying issue? Or run anybody into the same issue before? Any hints appreciated. Thanks.

like image 481
dasheddot Avatar asked Mar 07 '13 10:03

dasheddot


People also ask

What is the default timeout of Selenium WebDriver?

The default value of timeout is 0. This method is generally used for JavaScript commands in Selenium. If we omit setting time for the script, the executeAsyncScript method can encounter failure due to the more time consumed by the JavaScript to complete execution.

What is Pageload timeout in Selenium?

The pageLoadTimeout is the method used to set the time for the entire page load prior to throwing an exception. If the timeout time is set to negative, then the time taken to load the page is endless. This timeout is generally used with the navigate and manage methods.

What is script timeout in Selenium?

setScriptTimeout(); This is used to set the amount of time the WebDriver must wait for an asynchronous script to finish execution before throwing an error. If the timeout is negative, then the script will be allowed to run indefinitely.


2 Answers

I got this same error: .NET WebDriver: 2.37, FF: 25.0.1. I noticed that Firefox was locking up until I exited my test application, so I built the debug version of Firefox and found that the lock-up happened when it was writing to stderr. This gave me the clue to change the webdriver code so that it no longer redirects standard out and error and this solved my problem. It seems like the WebDriver is blocking the std error in some way. From MSDN:

Synchronous read operations introduce a dependency between the caller reading from the StandardError stream and the child process writing to that stream. These dependencies can cause deadlock conditions...

More info here.

For anyone wanting to make the same tweak I did: -

  1. Get the Selenium source. Then check out the same code branch that you are using.

  2. In FireFoxBinary.cs:

    i. Wherever you find RedirectStandardError = true, change to RedirectStandardError = false.

    ii. Wherever you find RedirectStandardOutput = true, change to RedirectStandardOutput = false. (for non-Windows, there is also one in Executable.cs)

    iii. In ConsoleOuput, change 'return this.stream.ReadToEnd()', to 'return ""'

  3. Build and replace WebDriver.dll with yours.

Disclaimer: This worked for me, but your issue might be different. Also as far as I can tell, this has no adverse effects other than disabling the console output, but there may be other side effects that I am unaware of.

I would be interested to know if anyone else finds the same.

Since I have solved my problem, I will not dig any deeper. If anyone a Selenium group member wants more info / logs / tweaks I would be happy to do so.

Hopefully this will get fixed soon.

Update

It appears that Firefox v25 is not currently supported. See this comment.

Update 25th Feb 2014

See this update:

Okay, this issue in general does not manifest itself in IE, or so it seems from the comments. I'd like people to try with Firefox and Chrome, and the .NET bindings 2.40.0 (will be the next release at the time of this writing) or later, and see if this is still happening.

I've seen fewer reports of this happening in Chrome since 2.35.0, so I need to know if this is still an issue with the .NET bindings and a recent chromedriver.exe.

2.40.0 may have a fix for at least one of the issues that may cause this in Firefox.

This solved the problem for me. Looking at the change log, there is a commit from 1/31/2014 to remove console logging redirection:

"No longer redirecting console output for Firefox in .NET bindings." 

Which is the workaround I used here. So, it all makes sense.

like image 186
acarlon Avatar answered Oct 14 '22 15:10

acarlon


Happened to me in four different scenarios:

  1. The cause was that the window handle I was querying was already closed or in closing stages. If this is the case, you better check that the window still exist before querying it. If you want to avoid the long timeout period of 60 seconds, you should change the way you create the Firefox instance to decrease the 60 seconds delay:

    new FirefoxDriver("FfBinaryPath", FfProfileInstance, TimeSpan.FromSeconds(5));

  2. The cause was the flash plugin 'Protected Mode'. This scenario happened to me only under windows 7 and 8 when they ran under Jenkins job, the timeout did not happened sporadically. In order to fix it, I ran my Firefox selenium instance with the flash security mode disabled:

    FfProfile.SetPreference("dom.ipc.plugins.flash.disable-protected-mode", true);

  3. Another cause, also non sporadic, under Jenkins and related to Flash, happened when using Firefox version 45. In order to resolve this issue I had to downgrade to version 44 or alteratively uninstall Flash.

  4. Internal browser reason: Sometimes the browser takes more than one minute to react Selenium calls. In such case, setting the browser command timeout above 60 seconds can solve the issue. for example:

    new FirefoxDriver("FfBinaryPath", FfProfileInstance, TimeSpan.FromMinutes(3));

like image 23
Nir Avatar answered Oct 14 '22 16:10

Nir