2011/03/03

Firefox WebDriver on Windows Behind HTTP Proxy

Playing with Selenium (2.0a7) I was quite suprised that FirefoxDriver does not recognize HTTP proxy. As I wanted my code to work behind firewall I was pushed to do some "research" on the topic and found working solution using Proxy and FirefoxProfile . I hope publishing it can help somebody with the same problem:
 
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

...

Proxy proxy = new Proxy();
proxy.setAutodetect(true);
//hard-coded: proxy.setProxyAutoconfigUrl("http://pac.your.com");
FirefoxProfile profile = new FirefoxProfile();
profile.setProxyPreferences(proxy);
WebDriver driver =  new FirefoxDriver (profile);