2013-10-07 15 views
9

Firefox için aşağıdaki gibi proxy ayarlarını yapılandırabilirim.Selenium Java'da Chrome için Proxy ayar nasıl ayarlanır

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); 

Ancak, Chrome için de ayarlamam gerekiyor .. Herhangi biri bana nasıl yardımcı olabilir?

Teşekkür Raj

cevap

10

Bunu, DesiredCapabilities sınıfını kullanarak deneyebilirsiniz:

DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=http://user:[email protected]:8080")); 
WebDriver driver = new ChromeDriver(capabilities); 
+0

Yani --proxy-sunucu olduğu gibi vermeliyim? – user1140680

+0

YA DA Sadece bunu mı vermeliyim? http: // user: [email protected]: 8080 – user1140680

+0

sadece kendi ayarlarınızı kullanın: 'özellikler.setCapability (" chrome.switches ", Arrays.asList (" --proxy-server = http: // "+ CONFIG. getProperty ("username") + ":" + CONFIG.getProperty ("password") + "@" + CONFIG.getProperty ("hostname"))); ' – Farlan

-3

bu kodu deneyin: Burada

FirefoxProfile profile = new FirefoxProfile(); 

profile.setPreference("network.proxy.type", ProxyType.AUTODETECT.ordinal()); 

WebDriver driver = new FirefoxDriver(profile); 

birer tane daha çözüm .... Benim için çalışmış

+0

Yalnızca Chrome sürücüsü hakkında soru sordu. – GhostCKY

İlgili konular