Tuesday, November 29, 2011

OpenQA.Selenium.WebDriverException : Failed to start up socket within 45000

If you have tried using the FluentAutomation with Selenium recently or in fact the Selenium WebDriver API directly within an automated test using something like NUnit, you might have encountered the following exception when used with Firefox:

 OpenQA.Selenium.WebDriverException : Failed to start up socket within 45000
  
 at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.ConnectToBrowser(Int64 timeToWaitInMilliSeconds)  
 at OpenQA.Selenium.Firefox.Internal.ExtensionConnection.Start()  
 at OpenQA.Selenium.Firefox.FirefoxDriver.StartClient()  
 at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxBinary binary, FirefoxProfile profile, TimeSpan commandTimeout)  
 at FluentAutomation.SeleniumWebDriver.AutomationProvider.Navigate(Uri pageUri)  
 at FluentAutomationDemo.Integration.TestClass1.Test() in Class1.cs: line 19   


Figure 1: Selenium test failure in Visual Studio

The latest version of the FluentAutomation uses the Selenium.WebDriver v2.8. This FluentAutomation can be installed via NuGet using the Package Manager Console:

 PM> Install-Package FluentAutomation.SeleniumWebDriver  

Alternatively, you can get the code on GitHub here: https://github.com/stirno/FluentAutomation The C# code I used to generate this error looks like the following:

 using FluentAutomation.API.Enumerations;  
 using NUnit.Framework;  
 namespace FluentAutomationDemo.Integration  
 {  
   public class TestClass1 : FluentAutomation.SeleniumWebDriver.FluentTest  
   {  
     [Test]  
     public void Test()  
     {  
       I.Use(BrowserType.Firefox);  
       I.Open("http://www.google.com");  
       I.Enter("Fluent Automation API").In("#lst-ib");  
     }  
   }  
 }  

So as you can see, it is simply trying to insert Fluent Automation API in the search box of a Google page using FireFox. It seems the Selenium WebDriver does not support the latest version of Firefox which is at the time of writing: 8.0.1. A workaround is to downgrade to Firefox v7.0.1.


To do this you then need to uninstall Firefox and download an old version from here (you can't get the old versions from the Firefox site): http://www.oldapps.com/firefox.php

Figure 2: Removing Firefox 8.0.1
By default the Firefox settings it set to auto update to the latest version available. You can turn this off thankfully.

To turn off the auto-update feature, simply un-tick the Firefox check box as in Figure 3 below, then click OK.

Figure 3: Firefox advanced options
Rerun the unit tests and all should be well.

4 comments:

Anonymous said...

Thanks for the steps Simon! This was about to drive me crazy. On a related note, I've found that going to About->Help in Firefox will automagically download and install the latest version. So make sure to turn the update settings off first thing.

Simon Hart said...

It's annoying that Firefox defaults to upgrading the application without the users say so. I'd expect it to at least at the user what they would like to do when they install the browser.

I think if you installed the Selenium Firefox plugin, you do get notified that upgrading will break Selenium.

I can only guess (without running something like TcpView) that the port Firefox listens on for Webdriver interaction has now changed to something that Selenium doesn't expect.

Simon

stirno said...

Simon, thanks for posting the steps to fix this. Wish I'd of seen it earlier.

The latest in source builds against a newer version of Selenium and is tested to work up to Firefox 10 now.

- stirno, FluentAutomation

Simon Hart said...

Thanks stirno, I'll be sure to update this blog post and check it out.

--
Simon