use of net.lightbody.bmp.BrowserMobProxyServer in project java.webdriver by sayems.
the class BrowserThreads method getDriver.
private WebDriver getDriver(boolean useBrowserMobProxy) {
if (null != webdriver && usingBrowserMobProxy != useBrowserMobProxy) {
webdriver.quit();
webdriver = null;
}
if (null == webdriver) {
Proxy proxy = null;
if (proxyEnabled || useBrowserMobProxy) {
if (useBrowserMobProxy) {
usingBrowserMobProxy = true;
browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.start();
if (proxyEnabled) {
browserMobProxy.setChainedProxy(new InetSocketAddress(proxyHostname, proxyPort));
}
proxy = ClientUtil.createSeleniumProxy(browserMobProxy);
} else {
proxy = new Proxy();
proxy.setProxyType(MANUAL);
proxy.setHttpProxy(proxyDetails);
proxy.setSslProxy(proxyDetails);
}
}
determineEffectiveDriverType();
DesiredCapabilities desiredCapabilities = selectedDriverType.browser.getDesiredCapabilities(proxy);
instantiateWebDriver(desiredCapabilities);
}
return webdriver;
}
use of net.lightbody.bmp.BrowserMobProxyServer in project opennms by OpenNMS.
the class DatabaseReportIT method customizeCapabilities.
// setup proxy and response filter
@Override
protected void customizeCapabilities(DesiredCapabilities caps) {
proxy = new BrowserMobProxyServer();
proxy.start(0);
proxy.addResponseFilter(new ResponseFilter() {
@Override
public void filterResponse(HttpResponse response, HttpMessageContents contents, HttpMessageInfo messageInfo) {
if (isReportDownloadResponse(response)) {
LOG.info("Report download response received with headers: {}", response.headers().entries());
try (ByteArrayInputStream input = new ByteArrayInputStream(contents.getBinaryContents());
FileOutputStream output = new FileOutputStream(getFile())) {
ByteStreams.copy(input, output);
} catch (IOException e) {
Throwables.propagate(e);
}
}
}
});
// configure the Browser Mob Proxy as a desired capability
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
caps.setCapability(CapabilityType.PROXY, seleniumProxy);
}
Aggregations