Search in sources :

Example 1 with BrowserMobProxyServer

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;
}
Also used : Proxy(org.openqa.selenium.Proxy) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) InetSocketAddress(java.net.InetSocketAddress) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) BrowserMobProxyServer(net.lightbody.bmp.BrowserMobProxyServer)

Example 2 with BrowserMobProxyServer

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);
}
Also used : Proxy(org.openqa.selenium.Proxy) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy) ByteArrayInputStream(java.io.ByteArrayInputStream) FileOutputStream(java.io.FileOutputStream) ResponseFilter(net.lightbody.bmp.filters.ResponseFilter) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpMessageInfo(net.lightbody.bmp.util.HttpMessageInfo) IOException(java.io.IOException) BrowserMobProxyServer(net.lightbody.bmp.BrowserMobProxyServer) HttpMessageContents(net.lightbody.bmp.util.HttpMessageContents)

Aggregations

BrowserMobProxy (net.lightbody.bmp.BrowserMobProxy)2 BrowserMobProxyServer (net.lightbody.bmp.BrowserMobProxyServer)2 Proxy (org.openqa.selenium.Proxy)2 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ResponseFilter (net.lightbody.bmp.filters.ResponseFilter)1 HttpMessageContents (net.lightbody.bmp.util.HttpMessageContents)1 HttpMessageInfo (net.lightbody.bmp.util.HttpMessageInfo)1 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)1