/** * This will sttempt to use the system's proxy settings. * * @return a proxy object with the system's default proxy configured in it. */ public Proxy getSystemProxy() { return new Proxy() .setProxyType(Proxy.ProxyType.SYSTEM); } }
/** * This will not use a proxy and expects a direct connection to the internet. * * @return a proxy object that does not use proxies. */ public Proxy getDirectProxy() { return new Proxy() .setProxyType(Proxy.ProxyType.DIRECT); }
/** * Valid inputs are system, autodetect, direct or http://{hostname}:{port} * * <p>This does not currently cope with PAC (Proxy auto-configuration from URL) * * @param proxyProperty the string representing the proxy required * @return a Selenium {@link Proxy} representation of proxyProperty */ public static Proxy createProxy(String proxyProperty) { Proxy proxy = new Proxy(); switch (proxyProperty.toLowerCase()) { case "system": logger.debug("Using system proxy"); proxy.setProxyType(Proxy.ProxyType.SYSTEM); break; case "autodetect": logger.debug("Using autodetect proxy"); proxy.setProxyType(Proxy.ProxyType.AUTODETECT); break; case "direct": logger.debug("Using direct i.e. (no) proxy"); proxy.setProxyType(Proxy.ProxyType.DIRECT); break; default: return createManualProxy(proxyProperty); } return proxy; }
/** * This is a proxy which will have its settings automatically configured. * * @return a proxy object which will try to automatically detect the proxy settings. */ public Proxy getAutodetectProxy() { return new Proxy() .setProxyType(Proxy.ProxyType.AUTODETECT) .setAutodetect(true); }
/** * If the proxy can be configured using a PAC file at a URL, set this value to the location of this PAC file. * * @param pacUrl is the url to the Proxy PAC file * * @return a proxy object with its proxies configured automatically using a PAC file. */ public Proxy getConfigUrlProxy(String pacUrl) { return new Proxy() .setProxyType(Proxy.ProxyType.PAC) .setProxyAutoconfigUrl(pacUrl); }
/** * 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; }
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);
/** * Returns the Proxy this client wraps, in form of a Selenium Proxy configuration object. * * @return Selenium Proxy configuration object */ public Proxy asSeleniumProxy() { Proxy seleniumProxyConfig = new Proxy(); seleniumProxyConfig.setProxyType(Proxy.ProxyType.MANUAL); seleniumProxyConfig.setHttpProxy(asHostAndPort()); return seleniumProxyConfig; }
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 Proxy(Map<String, ?> raw) { if (raw.containsKey("proxyType") && raw.get("proxyType") != null) { setProxyType(ProxyType.valueOf(((String) raw.get("proxyType")).toUpperCase()));
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; }
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; }
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; }
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; }
/** * 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; }