我正在使用BrowserMob(http://bmp.lightbody.net/)设置ChromeDriver来拦截HTTP响应。
ProxyServer proxyServer = null;
proxyServer = new ProxyServer(9101);
proxyServer.start();
proxyServer.setCaptureContent(true);
proxyServer.setCaptureHeaders(true);
Proxy proxy = proxyServer.seleniumProxy();
proxy.setHttpProxy("localhost:9101");
proxyServer.addResponseInterceptor(new ResponseInterceptor() {
@Override
public void process(BrowserMobHttpResponse response, Har har) {
if (response.getRawResponse().getStatusLine().getStatusCode() == 500) {
// do something
}
}
});
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver", "seleniumdrivers/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=nl");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
this.driver = new ChromeDriver(capabilities);
运行Selenium测试时,每个页面加载速度都非常慢。没有代理,它工作正常。有人知道原因/解决方案吗?
在日志控制台中,将显示以下消息:jan 10, 2014 12:58:06 PM net.sf.uadetector.datastore.AbstractUpdateOperation isUpdateAvailable
INFO: Can not check for an updated version. Are you sure you have an established internet connection?
不知道这是否相关。
在在线网站(非本地服务器)上运行Selenium测试,这意味着我有互联网连接