39

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.

dasheddot
  • 2,936
  • 4
  • 26
  • 33
  • What browser & what version of that browser? – Arran Mar 07 '13 at 10:09
  • Just curious, has this happened more since the update to FF 19? – Arran Mar 07 '13 at 10:16
  • I would say no. It could be that the issues starts when we updated from webdriver 2.28 to 2.30. Since we get this issues we thought it may be solved by updating firefox too. But it didn't help for now. – dasheddot Mar 07 '13 at 10:18
  • 4
    This problem is a manifestation of [this issue](http://code.google.com/p/selenium/issues/detail?id=4248) in the issue tracker. The error message was changed in [this changeset](http://code.google.com/p/selenium/source/detail?r=a26a61aa7bdde6a3a9e5174bdd573981a6e778fe) in the code base. There is a [blog post](http://jimevansmusic.blogspot.com/2012/11/net-bindings-whaddaymean-no-response.html) that explains the difficulties of resolving the issue definitively. – JimEvans Mar 07 '13 at 12:36
  • @JimEvans Thanks for you great explanation in your blog post. So it seems I can't work around this issue? Its even more interesting that we didn't run into this issue before and the test I am speaking about sucessfully ran the last decade or so. Just after updating 2.28 to 2.30 this issue seems to happen. And even the server is exactly in the same configuration. Although I got it, that you never had this issue in production, do you have any hints how I may work around it in the meanwhile? ;) – dasheddot Mar 07 '13 at 13:00
  • 1
    Is anything changing in the page when the file is 100% complete? Something which was not there before. (for example text saying 'file upload is now complete'. If the answer is yes you can write a simple loop trying to grab this element for a considerable amount of time (120 sec) before attempting to click on the upload button. If it fails it means that something went wrong with the upload or the website is running considerably slow. – Xwris Stoixeia Mar 15 '13 at 12:39
  • On file upload forms, I "always" try to use a webservice or servlet endpoint directly instead of using the form. It is much more reliable that way if you have access to such a thing. – djangofan May 06 '13 at 23:22
  • @djangofan Good point, but since UI tests are sort of integration tests our problem is that we want to test the UI. The UI is a form where ONE of the fields is the upload (which is required), so if we want to test this form we are not really able to go around uploading a file. – dasheddot May 07 '13 at 10:00
  • @dasheddot - I hear what you are saying and I agree but you must also consider when something is "not worth testing" because the likelihood of finding a bug in a standard file upload control is low. The important aspect of the file upload action is not the control itself, but its the service that responds to the control. If you are trying to get speed metrics from the control, that may be another matter but I doubt that you are. – djangofan May 07 '13 at 17:21
  • @djangofan To explain it further, we also want to test the logic placed inside the UI (lot of javascript). For instance we want to test if the file extension white list gets checked on the client. Of course the service itself checks for the same logic, but to be convenient we need to check these rules in javascript before the user can upload big files just to get the message afterwards that the extension was not allowed. So even if I got your point, and agree, I need to test the UI itself (too). – dasheddot May 07 '13 at 20:49

8 Answers8

8

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.

acarlon
  • 16,764
  • 7
  • 75
  • 94
  • With Selenium.2.43.1, there is no parameter called RedirectStandardError on FireFoxBinary.cs. I am getting the same error with Firefox32 on my build server... – demokritos May 10 '15 at 02:50
  • @demokritos - as per the last update a fix was put into 2.40.0 and later to remove the redirection. So, the issue that you are having is likely to be caused by a different problem. – acarlon May 11 '15 at 05:12
7

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

Community
  • 1
  • 1
Nir
  • 1,836
  • 23
  • 26
4

I had the same error with timing out. I was using the IEDriverServer (64bit) and on long sendKey commands it would timeout.

The reason being is that the default timeout seems to be 60 seconds.

What fixed my issue is that I instantiated the driver with a method that enables you to enter in the location of the IEDriverServer, the options for the driver AND the timeout value.

Link to documentation : http://seleniumhq.github.io/selenium/docs/api/dotnet/

public InternetExplorerDriver(
    string internetExplorerDriverServerDirectory,
    InternetExplorerOptions options,
    TimeSpan commandTimeout
)

Parameters

  1. InternetExplorerDriverServerDirectory:
    • Type : System.String
    • The full path to the directory containing IEDriverServer.exe
  2. options
    • Type : OpenQA.Selenium.IE.InternetExplorerOptions
    • The InternetExplorerOptions used to initialize the driver
  3. commandTimeout
    • Type : System.TimeSpan
    • The maximum amount of time to wait for each command

My code

InternetExplorerOptions options = new InternetExplorerOptions();
        IWebDriver driver = new InternetExplorerDriver("C:/Users/jeff/AppData/Local/Microsoft/WindowsApps", options, TimeSpan.FromSeconds(120));
tanz
  • 335
  • 3
  • 12
3

In my case the page is simply not fully loaded. Some facebook plugin seems to load too long. I tried catching the exception and manipulating the uncomplete dom, but this didn't give me any results. :(

John

Iwan1993
  • 1,669
  • 2
  • 17
  • 25
1

We faced a similar issue on our project. The problem had nothing to do with Selenium or our app. It was timing out because the build server config for that project was supposed to timeout in 5 minutes. But all our tests were not getting completed in 5 minutes, hence the build was failing due to timeout issues randomly.

Also we had a problem with firefox-19, the tests used to fail randomly. Somehow, firefox-10 only worked for our selenium tests.

Infant Dev
  • 1,659
  • 8
  • 24
  • 48
1

Try this code:

  DesiredCapabilities caps = DesiredCapabilities.Firefox();   

 //set the timeout to 120 seconds
 IWebDriver driver = new RemoteWebDriver(new Uri("<app_url>"), caps, TimeSpan.FromSeconds(120));
9ikhan
  • 1,177
  • 3
  • 11
  • 22
1

I had the same issue as well but only on Firefox driver. Turns out it might be related to when you use the driver Navigate method and it tries to interact too fast with the page. Calling below code fix it for me on Navigate (I also recommend to use it before FindElement as well):

public void VerifyPageIsLoaded()
{
    var pageLoaded = false;

    for (var i = 0; i < DefaultTimeout.Timeout.Seconds; i++)
    {
        Thread.Sleep(1000);

        if (WebDriver.ExecuteJavaScript<string>("return document.readyState").Equals("complete"))
        //jQuery.active might cause problems on some browser or browserstack so I commented it out
        //&& WebDriver.ExecuteJavaScript<bool>("return jQuery.active == 0").Equals(true))
        {
            pageLoaded = true;
            break;
        }

        Thread.Sleep(1000);
    }

    if (!pageLoaded)
    {
        throw new Exception("Page was not with complete state)!");
    }
}
Rain9333
  • 570
  • 4
  • 22
0
public static IWebElement WaitForElementVisible(By selector, uint timeout = Config.DefaultTimeoutSec)
    {
        IWebDriver driver = Browser.Instance.Driver;

        if (timeout > 0)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));

            wait.Until(ExpectedConditions.ElementIsVisible(selector));
            return driver.FindElement(selector);
        }
        else
        {
            // Search for element without timeout 
            return driver.FindElement(selector);
        }
    }

We use this to prevent such Element not found failures and it works like a charm.

There is also a different Version if the Element can be there, but doesn't have to be visible.

Just use ExpectedConditions.ElementExists(selector) instead of ExpectedContitions.ElementIsVisible(selector)

edit: Browser.Instance.Driver is a class containing the instanced driver

Dominik Lemberger
  • 2,287
  • 2
  • 21
  • 33