follow me icons

Sunday, September 26, 2010

Firefox Proxy configuration using Selenium Webdriver and Capybara

Quite often we have to run the automation test within the proxy setting. The default browser profile setup that Capybara use is the anonymous profile which does not use proxy setting by default. This will cause problem as the browser will not be able to access the webpage.

To see all of the available configuration in Firefox simply type "about:config" on the firefox address bar. You will then see the following screen:

One solution is to set the browser profile to use a proxy setting. The code can be placed inside the env.rb files to override the anonymous browser profile that Capybara uses.

# Need to override the driver to setup our proxy profile
class Capybara::Driver::Selenium
def self.driver
unless @driver
profile =
profile["network.proxy.type"] = 1
profile["network.proxy.http"] = "proxy setting"
profile["network.proxy.http_port"] = 8080
@driver = Selenium::WebDriver.for(:firefox, :profile => profile)

at_exit do

If you need to use the Automatic proxy configuration (pac file) URL then you would need to add the following line:


And change the network.proxy.type into 2

profile["network.proxy.type"] = 1

If you need Capybara to use a different browser other than Firefox you can change the webdriver browser's profile. To change the default profile for other browsers you just need to change the @driver to use the browser that you want.

@driver = Selenium::WebDriver.for :ie
@driver = Selenium::WebDriver.for :chrome

Please note that webdriver currently only supports Firefox, IE and chrome.


  1. As of Capybara 0.4.0, you would need to use the following code

    Capybara.register_driver :selenium do |app|
    profile =
    profile["network.proxy.type"] = 1
    profile["network.proxy.http"] = "proxy setting"
    profile["network.proxy.http_port"] = 8080, :browser => :firefox, :profile => profile)

  2. If you get this error
    uninitialized constant Selenium (NameError)
    ./features/support/env.rb:19:in `block in '

    Try adding require "selenium-webdriver" on the env.rb file

  3. Hi I tried this way and it helped me set manual network setting in fire fox .

    address : "x.x.x.x:8080" and Import respective packages

    enter code here

    public class SeleniumUtil

    WebDriver driver;


    String PROXY = "";

    org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.PROXY, proxy);
    driver = new FirefoxDriver(cap);

    @BeforeSuite(alwaysRun = true)
    public void setupBeforeSuite()

  4. Hi BA,

    profile =

    The above statement does not work with Internet explorer so it says and suggestion?
    uninitialized constant Selenium::WebDriver::IE (NameError)