8

我正在使用 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 测试,这意味着我有互联网连接

4

0 回答 0