Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Proxy setting for Chrome in Selenium Java

I am able to set proxy settings for Firefox as below.

org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setProxyType(ProxyType.MANUAL); 

proxy.setHttpProxy(CONFIG.getProperty("hostname"));
proxy.setSslProxy(CONFIG.getProperty("hostname"));
proxy.setFtpProxy(CONFIG.getProperty("hostname"));
proxy.setSocksUsername(CONFIG.getProperty("username"));
proxy.setSocksPassword(CONFIG.getProperty("password"));
FirefoxProfile fp = new FirefoxProfile();
fp.setProxyPreferences(proxy);

driver = new FirefoxDriver(fp);
builder = new Actions(driver); 
bckdbrowser = new WebDriverBackedSelenium(driver, ConfigReader.ENVIRONMENT_URL);

But I need to setup for Chrome as well.. Can any one assist me how to do ?

Thanks Raj

like image 817
user1140680 Avatar asked Oct 07 '13 12:10

user1140680


1 Answers

You can try using the DesiredCapabilities class, like this:

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:[email protected]:8080"));
WebDriver driver = new ChromeDriver(capabilities);
like image 149
Farlan Avatar answered Sep 21 '22 13:09

Farlan