Proxy proxy=startProxy(); proxy.setProxyType(ProxyType.MANUAL); proxy.setNoProxy(""); ChromeOptions options = new ChromeOptions(); DesiredCapabilities dc = DesiredCapabilities.chrome(); dc.setCapability(CapabilityType.PROXY, proxy); System.setProperty("webdriver.chrome.driver",sChromeDriverPath); dc.setCapability(ChromeOptions.CAPABILITY, options); WebDriver driver = new ChromeDriver(dc);
if (rawData instanceof List) { setNoProxy(String.join(", ", (List) rawData)); } else { setNoProxy((String) rawData);
/** * @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); }
/** * 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); }
public Proxy getProxy() { ProxyConfig proxyConfig = getProxyConfig(); Proxy proxy = new Proxy(); proxy.setProxyType(proxyConfig.getType()); if (proxyConfig.getType() == ProxyType.PAC) { proxy.setProxyAutoconfigUrl(proxyConfig.getPac()); // manual proxy configuration } else if (proxyConfig.getType() == ProxyType.MANUAL) { proxy.setHttpProxy(proxyConfig.getAddressAndPort()); proxy.setSslProxy(proxyConfig.getAddressAndPort()); proxy.setFtpProxy(proxyConfig.getAddressAndPort()); if (proxyConfig.getLogin() != null && proxyConfig.getPassword() != null) { proxy.setSocksUsername(proxyConfig.getLogin()); proxy.setSocksPassword(proxyConfig.getPassword()); } if (proxyConfig.getExclude() != null) { proxy.setNoProxy(proxyConfig.getExclude().replace(";", ",")); } } return proxy; }