Selenium-启动Firefox代理的代码
上一篇 /
下一篇 2013-12-16 14:43:07
/ 个人分类:Selenium
有时候需要设置Firefox的代理,才能访问被
测试的网站。
String proxyIp = "10.158.140.94";
int proxyPort = 80;
FirefoxProfile profile = new FirefoxProfile();
// 使用代理
profile.setPreference("network.proxy.type", 1);
// http协议代理配置
profile.setPreference("network.proxy.http", proxyIp);
profile.setPreference("network.proxy.http_port", proxyPort);
profile.setPreference("network.proxy.ssl", proxyIp);
profile.setPreference("network.proxy.ssl_port", proxyPort);
// 所有协议公用一种代理配置,如果单独配置,这项设置为false
profile.setPreference("network.proxy.share_proxy_settings", true);
// 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯
profile.setPreference("network.proxy.no_proxies_on", "localhost");
// 以代理方式启动firefox
FirefoxDriver driver = new FirefoxDriver(profile);
收藏
举报
TAG: