server = new BrowserMobProxyServer(); server.start(0); Proxy proxy = ClientUtil.createSeleniumProxy(server); proxy.setSslProxy("trustAllSSLCertificates");
public void startBrowserWithProxy() { Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy); seleniumProxy.setSslProxy("localhost:" + proxy.getPort()); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.PROXY, seleniumProxy); System.setProperty("webdriver.chrome.driver", "C:/Users/Madis/Documents/chromedriver.exe"); WebDriver driver = new ChromeDriver(capabilities); }
public void setSslProxy(String proxyHost) { if (!StringUtils.equalsIgnoreCase(proxyHost, "none")) { proxy = new Proxy(); proxy.setSslProxy(proxyHost); capabilities.setCapability(CapabilityType.PROXY, proxy); } }
/** * Creates a Selenium Proxy object using the specified connectableAddressAndPort as the HTTP proxy server. * * @param connectableAddressAndPort the network address (or hostname) and port the Selenium Proxy will use to reach its * proxy server (the InetSocketAddress may be unresolved). * @return a Selenium Proxy instance, configured to use the specified address and port as its proxy server */ public static org.openqa.selenium.Proxy createSeleniumProxy(InetSocketAddress connectableAddressAndPort) { Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); String proxyStr = String.format("%s:%d", connectableAddressAndPort.getHostString(), connectableAddressAndPort.getPort()); proxy.setHttpProxy(proxyStr); proxy.setSslProxy(proxyStr); return proxy; }
public void setProxy(String proxyHost) { if (!StringUtils.equalsIgnoreCase(proxyHost, "none")) { proxy = new Proxy(); proxy.setFtpProxy(proxyHost) .setHttpProxy(proxyHost) .setSslProxy(proxyHost); capabilities.setCapability(CapabilityType.PROXY, proxy); } }
public org.openqa.selenium.Proxy seleniumProxy() throws UnknownHostException { Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL); String proxyStr = String.format("%s:%d", getLocalHost().getCanonicalHostName(), getPort()); proxy.setHttpProxy(proxyStr); proxy.setSslProxy(proxyStr); return proxy; }
public void in(DesiredCapabilities capabilities) { String proxyUrl = ThucydidesSystemProperty.SERENITY_PROXY_HTTP.from(environmentVariables); String proxyPort = ThucydidesSystemProperty.SERENITY_PROXY_HTTP_PORT.from(environmentVariables); String sslProxy = ThucydidesSystemProperty.SERENITY_PROXY_SSL.from(environmentVariables, proxyUrl); String sslProxyPort = ThucydidesSystemProperty.SERENITY_PROXY_SSL_PORT.from(environmentVariables); Proxy proxy = new Proxy(); if ((proxyUrl != null) && (!proxyUrl.isEmpty())) { JsonObject json = new JsonObject(); if (StringUtils.isNotEmpty(proxyUrl)) { proxy.setHttpProxy(proxyUrl + ":"+ proxyPort); } if (StringUtils.isNotEmpty(sslProxy)) { proxy.setSslProxy(sslProxy + ":"+ sslProxyPort); } if (StringUtils.isNotEmpty(sslProxyPort)) { json.addProperty("sslProxyPort", sslProxyPort); } capabilities.setCapability(CapabilityType.PROXY, proxy); } } }
private void setNetworkCapabilities(final DesiredCapabilities capabilities) { final String proxyHost = configuration.getNetworkProxyHost(); if (StringUtils.isNotEmpty(proxyHost)) { final int proxyPort = configuration.getNetworkProxyPort(); final String proxyHostAndPort = proxyHost + ":" + proxyPort; final org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy(); proxy.setHttpProxy(proxyHostAndPort).setFtpProxy(proxyHostAndPort).setSslProxy(proxyHostAndPort); capabilities.setCapability(CapabilityType.PROXY, proxy); LOG.info("Proxy set to {}", proxyHostAndPort); } }
@Override public Proxy seleniumProxy() throws UnknownHostException { return server.asSeleniumProxy() .setHttpProxy(String.format("%s:%d", proxyManager.getServer(), getPort())) .setSslProxy(String.format("%s:%d", proxyManager.getServer(), getPort())); }
/** * @return - A {@link Proxy} object that represents the Proxy server to be used. */ public static Proxy createProxyObject() { Proxy proxy = new Proxy(); String proxyHost = String.format("%s:%s", getProperty(ConfigProperty.SELENIUM_PROXY_HOST), getProperty(ConfigProperty.SELENIUM_PROXY_PORT)); proxy.setHttpProxy(proxyHost); proxy.setFtpProxy(proxyHost); proxy.setSslProxy(proxyHost); return proxy; }
private static Proxy createManualProxy(String proxyProperty) { String proxyString = getProxyURL(proxyProperty); logger.debug("All protocols to use proxy address: {}", proxyString); Proxy proxy = new Proxy(); proxy.setProxyType(Proxy.ProxyType.MANUAL) .setHttpProxy(proxyString) .setFtpProxy(proxyString) .setSslProxy(proxyString); return proxy; }
/** * @Title: browserProxySettings @Description: TODO @author * alterhu2020@gmail.com @param @param capability @param @param * proxysettings @return void return type @throws */ public static void ProxySettings(DesiredCapabilities capability, String proxysettings) { org.openqa.selenium.Proxy httpproxy = new org.openqa.selenium.Proxy(); httpproxy.setHttpProxy(proxysettings); httpproxy.setSslProxy(proxysettings); httpproxy.setNoProxy("localhost"); capability.setCapability(CapabilityType.PROXY, httpproxy); }
/** * @Title: browserProxySettings @Description: TODO @author * alterhu2020@gmail.com @param @param capability @param @param * proxysettings @return void return type @throws */ public static void ProxySettings(DesiredCapabilities capability, String proxysettings) { org.openqa.selenium.Proxy httpproxy = new org.openqa.selenium.Proxy(); httpproxy.setHttpProxy(proxysettings); httpproxy.setSslProxy(proxysettings); httpproxy.setNoProxy("localhost"); capability.setCapability(CapabilityType.PROXY, httpproxy); }
public Proxy getProxy() { Proxy proxy = null; if (proxyHost != null) { proxy = new Proxy(); proxy.setProxyType(ProxyType.MANUAL); proxy.setHttpProxy(proxyHost); proxy.setFtpProxy(proxyHost); proxy.setSslProxy(proxyHost); } return proxy; }
@Override public void afterPropertiesSet() throws Exception { if(enable) { server = new BrowserMobProxyServer(); server.start(); int port = server.getPort(); Proxy proxy = ClientUtil.createSeleniumProxy(server); proxy.setHttpProxy("127.0.0.1:" + port); proxy.setSslProxy("127.0.0.1:" + port); capabilities.setCapability(CapabilityType.PROXY, proxy); System.out.println("BrowserMobProxyServer@" + port); } }
private Capabilities getCapabilities() { final String proxyUrl = "localhost:" + proxyServerPort; final Proxy proxy = new Proxy() .setProxyType(Proxy.ProxyType.MANUAL) .setHttpProxy(proxyUrl) .setSslProxy(proxyUrl); final DesiredCapabilities desiredCapabilities = new DesiredCapabilities(config.getWebDriverCapabilities()); desiredCapabilities.setCapability(CapabilityType.PROXY, proxy); desiredCapabilities.setJavascriptEnabled(true); return desiredCapabilities; }
/** * Creates the DesiredCapabilities for an IE WebDriver. * @param proxyUrl * @return DesiredCapabilities */ protected static DesiredCapabilities createCapabilitiesIE(String proxyUrl) { DesiredCapabilities cap = DesiredCapabilities.internetExplorer(); cap.setCapability(CapabilityType.LOGGING_PREFS, createLoggingPreferences()); cap.setCapability("ignoreProtectedModeSettings", true); cap.setCapability("ignoreZoomSetting", true); if (StringUtils.isNotEmpty(proxyUrl)) { Proxy proxy = new Proxy(); proxy.setHttpProxy(proxyUrl).setFtpProxy(proxyUrl).setSslProxy(proxyUrl).setNoProxy(""); cap.setCapability(CapabilityType.PROXY, proxy); } return cap; }
/** * Creates the DesiredCapabilities for firefox. * @param proxyUrl * @param profile * @return DesiredCapabilities */ protected static DesiredCapabilities createCapabilitesFirefox(String proxyUrl, FirefoxProfile profile) { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); if (!proxyUrl.isEmpty()) { capabilities.setCapability(FirefoxDriver.PROFILE, profile); profile.setPreference("network.proxy.type", 1); Proxy proxy = new Proxy(); proxy.setHttpProxy(proxyUrl).setFtpProxy(proxyUrl).setSslProxy(proxyUrl).setNoProxy(""); capabilities.setCapability(CapabilityType.PROXY, proxy); } capabilities.setCapability(CapabilityType.LOGGING_PREFS, createLoggingPreferences()); return capabilities; }
/** * Create new Proxy from driver options. * * @param driverOptions driver options. * @return Proxy or null. */ public static Proxy newProxy(DriverOptions driverOptions) { if (!driverOptions.has(PROXY)) return null; Proxy proxy = new Proxy(); proxy.setProxyType(ProxyType.MANUAL); String ps = driverOptions.get(PROXY); proxy.setHttpProxy(ps) .setSslProxy(ps) .setFtpProxy(ps); if (driverOptions.has(NO_PROXY)) proxy.setNoProxy(driverOptions.get(NO_PROXY)); return proxy; }
/** * This returns a {@link Proxy} with HTTP, HTTPS and FTP hosts and ports configured as specified. * * * @param httpProxy is the http proxy host and port * @param httpsProxy is the https proxy host and port * @param ftpProxy is the ftp proxy host and port * @param socksProxy is the socks proxy host and port * @param noProxy is a comma separated list of hosts that will bypass the proxy * * @return a proxy object with the hosts manually specified. */ public Proxy getManualProxy(ProxyHostPort httpProxy, ProxyHostPort httpsProxy, ProxyHostPort ftpProxy, ProxyHostPort socksProxy, String noProxy) { return new Proxy() .setProxyType(Proxy.ProxyType.MANUAL) .setHttpProxy(httpProxy.toUnifiedForm()) .setSslProxy(httpsProxy.toUnifiedForm()) .setFtpProxy(ftpProxy.toUnifiedForm()) .setSocksProxy(socksProxy.toUnifiedForm()) .setNoProxy(noProxy); }