List of usage examples for org.openqa.selenium Proxy getHttpProxy
public String getHttpProxy()
From source file:com.atanas.kanchev.testframework.selenium.driverfactory.DesiredCapsFactory.java
License:Apache License
private List<String> applyPhantomJSProxySettings(List<String> cliArguments, Proxy proxySettings) { if (null == proxySettings) { cliArguments.add("--proxy-type=none"); } else {/* w w w. j a va 2s.co m*/ cliArguments.add("--proxy-type=http"); cliArguments.add("--proxy=" + proxySettings.getHttpProxy()); } return cliArguments; }
From source file:com.mgmtp.jfunk.web.JFunkHtmlUnitDriverImpl.java
License:Apache License
private void setProxy(final Proxy proxy) { if (proxy != null) { String fullProxy = proxy.getHttpProxy(); if (fullProxy != null) { int index = fullProxy.indexOf(":"); if (index != -1) { String host = fullProxy.substring(0, index); int port = Integer.parseInt(fullProxy.substring(index + 1)); setProxy(host, port);//from w w w. j av a 2 s .c om } else { setProxy(fullProxy, 0); } } } }
From source file:com.opera.core.systems.OperaProxy.java
License:Apache License
/** * Parse an instance of {@link Proxy}, merge and apply its configuration to the current Opera * instance./*from w w w .j a va2 s. co m*/ */ public void parse(Proxy proxy) { if (proxy.getProxyType() == Proxy.ProxyType.UNSPECIFIED) { return; } reset(); switch (proxy.getProxyType()) { case DIRECT: if (!product.is(MOBILE)) { setEnabled(false); } setUsePAC(false); break; case MANUAL: if (!product.is(MOBILE)) { setEnabled(true); } setUsePAC(false); // TODO(andreastt): HTTPS proxy // TODO(andreastt): SOCKS proxy if (proxy.getHttpProxy() != null) { setHttpProxy(proxy.getHttpProxy()); } if (proxy.getFtpProxy() != null) { setFtpProxy(proxy.getFtpProxy()); } break; case PAC: if (!product.is(MOBILE)) { setEnabled(true); } setUsePAC(true); if (proxy.getProxyAutoconfigUrl() != null) { setAutoconfigUrl(proxy.getProxyAutoconfigUrl()); } break; default: logger.warning("Unsupported proxy type: " + proxy.getProxyType()); } }
From source file:com.opera.core.systems.OperaSettingsCapabilitiesTest.java
License:Apache License
@Test public void proxySanitizeProxyObject() { Proxy proxy = new Proxy(); proxy.setHttpProxy("4.4.4.4"); Proxy sanitizedProxy = (Proxy) PROXY.sanitize(proxy); assertNotNull(sanitizedProxy);/*from w w w . ja v a 2 s. c om*/ assertThat(sanitizedProxy, is(instanceOf(Proxy.class))); assertEquals(proxy, sanitizedProxy); assertEquals("4.4.4.4", sanitizedProxy.getHttpProxy()); }
From source file:com.opera.core.systems.OperaSettingsCapabilitiesTest.java
License:Apache License
@Test public void proxySanitizeMap() { Map<String, ?> jsonProxy = ImmutableMap.of("httpProxy", "4.4.4.4"); Proxy sanitizedProxy = (Proxy) PROXY.sanitize(jsonProxy); assertNotNull(sanitizedProxy);//from w w w . ja v a2 s.c om assertThat(sanitizedProxy, is(instanceOf(Proxy.class))); assertEquals("4.4.4.4", sanitizedProxy.getHttpProxy()); }
From source file:phantomjs.PhantomJSDriver.java
License:Apache License
/** * In case this instance was required to handle the life-cycle of the PhantomJS process, that starts here. * Otherwise this is a "transparent" method. * * @param desiredCapabilities/*from w w w .jav a 2 s .co m*/ * @param requiredCapabilities * @throws WebDriverException */ @Override protected void startSession(Capabilities desiredCapabilities, Capabilities requiredCapabilities) throws WebDriverException { // Will launch a PhantomJS WebDriver process ONLY if this driver is not already using an external one if (!useExternalPhantomJS) { // Read PhantomJS executable and JS Driver path from the capabilities String executablePath = (String) desiredCapabilities.getCapability(CAPABILITY_PHANTOMSJS_EXEC_PATH); String driverPath = (String) desiredCapabilities.getCapability(CAPABILITY_PHANTOMJS_DRIVER_PATH); // Throw WebDriverException in case any of the previous two was not provided if (executablePath == null || driverPath == null || !new File(executablePath).exists() || !new File(driverPath).exists()) { throw new WebDriverException( "PhantomJSDriver: Path to PhantomJS Executable or Driver not provided/invalid"); } // Read the Proxy configuration Proxy proxy = (Proxy) desiredCapabilities.getCapability(CapabilityType.PROXY); // Prepare the parameters to pass to the PhantomJS executable on the command line String proxyParams = ""; if (proxy != null) { switch (proxy.getProxyType()) { case MANUAL: if (!proxy.getHttpProxy().isEmpty()) { //< HTTP proxy log(getSessionId(), "Reading Proxy Configuration", "Manual, HTTP", When.BEFORE); proxyParams = String.format("--proxy-type=http --proxy=%s", proxy.getHttpProxy()); } else if (!proxy.getSocksProxy().isEmpty()) { //< SOCKS5 proxy log(getSessionId(), "Reading Proxy Configuration", "Manual, SOCKS5", When.BEFORE); proxyParams = String.format("--proxy-type=socks5 --proxy=%s --proxy-auth=%s:%s", proxy.getSocksProxy(), proxy.getSocksUsername(), proxy.getSocksPassword()); } else { // TODO Other type of proxy not supported yet by PhantomJS log(getSessionId(), "Reading Proxy Configuration", "Manual, NOT SUPPORTED", When.BEFORE); } break; case PAC: // TODO Not supported yet by PhantomJS log(getSessionId(), "Reading Proxy Configuration", "PAC, NOT SUPPORTED", When.BEFORE); break; case SYSTEM: log(getSessionId(), "Reading Proxy Configuration", "SYSTEM", When.BEFORE); proxyParams = "--proxy-type=system"; break; case AUTODETECT: // TODO Not supported yet by PhantomJS log(getSessionId(), "Reading Proxy Configuration", "AUTODETECT, NOT SUPPORTED", When.BEFORE); break; case DIRECT: log(getSessionId(), "Reading Proxy Configuration", "DIRECT", When.BEFORE); proxyParams = "--proxy-type=none"; default: log(getSessionId(), "Reading Proxy Configuration", "NONE", When.BEFORE); proxyParams = ""; break; } } // Find a free port to launch PhantomJS WebDriver on String phantomJSPortStr = Integer.toString(PortProber.findFreePort()); log(getSessionId(), "Looking for a free port for PhantomJS WebDriver", phantomJSPortStr, When.AFTER); log(getSessionId(), "About to launch PhantomJS WebDriver", null, When.BEFORE); try { // Launch PhantomJS and wait for first output on console before proceeding phantomJSProcess = Runtime.getRuntime().exec(new String[] { executablePath, //< path to PhantomJS executable proxyParams, //< command line parameters for Proxy configuration driverPath, //< path to the PhantomJS Driver phantomJSPortStr //< port on which the Driver should listen on }); final BufferedReader reader = new BufferedReader( new InputStreamReader(phantomJSProcess.getInputStream())); while (reader.readLine() == null) { /* wait here for some output: once it prints, it's ready to work */ } useExternalPhantomJS = false; // PhantomJS is ready to serve. // Setting the HTTP Command Executor that this RemoteWebDriver will use setCommandExecutor(new HttpCommandExecutor(new URL("http://localhost:" + phantomJSPortStr))); } catch (IOException ioe) { // Log exception & Cleanup log(getSessionId(), null, ioe, When.EXCEPTION); stopClient(); throw new WebDriverException("PhantomJSDriver: " + ioe.getMessage(), ioe); } log(getSessionId(), "PhantomJS WebDriver ready", null, When.AFTER); } // We are ready to let the RemoteDriver do its job from here super.startSession(desiredCapabilities, requiredCapabilities); }