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.

Friday, November 11, 2011

Code formatter for blogs

I came across this site that allows for easy formatting of source code for displaying on blog posts. Pretty cool. This is a test post...
   public class StructureMapFilterProvider : FilterAttributeFilterProvider  
   {  
     /// <summary>  
     /// Structuremap instance.  
     /// </summary>  
     private readonly IContainer container;  
     /// <summary>  
     /// Initializes a new instance of the <see cref="StructureMapFilterProvider"/> class.  
     /// </summary>  
     /// <param name="container">The container.</param>  
     public StructureMapFilterProvider(IContainer container)  
     {  
       this.container = container;  
     }  
     /// <summary>  
     /// Intercept's GetFilters, then use the "BuildUp" feature of structuremap to avoid using decorators for property injection and this  
     /// involves coupling.  
     /// </summary>  
     /// <param name="controllerContext">The controller context.</param>  
     /// <param name="actionDescriptor">The action descriptor.</param>  
     /// <returns>A list of filters for the current context.</returns>  
     public override IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)  
     {  
       var filters = base.GetFilters(controllerContext, actionDescriptor);  
       if (filters != null)  
       {  
         foreach (var filter in filters)  
         {  
           this.container.BuildUp(filter.Instance);  
         }  
         return filters;  
       }  
       return default(IEnumerable<Filter>);  
     }  
   }  
Neat, I like it!