Java Code Examples for org.openqa.selenium.Proxy#setHttpProxy()

The following examples show how to use org.openqa.selenium.Proxy#setHttpProxy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonOutputTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldConvertAProxyCorrectly() {
  Proxy proxy = new Proxy();
  proxy.setHttpProxy("localhost:4444");

  MutableCapabilities caps = new DesiredCapabilities("foo", "1", Platform.LINUX);
  caps.setCapability(CapabilityType.PROXY, proxy);
  Map<String, ?> asMap = ImmutableMap.of("desiredCapabilities", caps);
  Command command = new Command(new SessionId("empty"), DriverCommand.NEW_SESSION, asMap);

  String json = convert(command.getParameters());

  JsonObject converted = new JsonParser().parse(json).getAsJsonObject();
  JsonObject capsAsMap = converted.get("desiredCapabilities").getAsJsonObject();

  assertThat(capsAsMap.get(CapabilityType.PROXY).getAsJsonObject().get("httpProxy").getAsString())
      .isEqualTo(proxy.getHttpProxy());
}
 
Example 2
Source File: ClientUtil.java    From browserup-proxy with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: DriverFactory.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
private void instantiateWebDriver(DriverType driverType) throws MalformedURLException {
    System.out.println(" ");
    System.out.println("Local Operating System: " + operatingSystem);
    System.out.println("Local Architecture: " + systemArchitecture);
    System.out.println("Selected Browser: " + selectedDriverType);
    System.out.println("Connecting to Selenium Grid: " + useRemoteWebDriver);
    System.out.println(" ");

    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();

    if (proxyEnabled) {
        Proxy proxy = new Proxy();
        proxy.setProxyType(MANUAL);
        proxy.setHttpProxy(proxyDetails);
        proxy.setSslProxy(proxyDetails);
        desiredCapabilities.setCapability(PROXY, proxy);
    }

    if (useRemoteWebDriver) {
        URL seleniumGridURL = new URL(System.getProperty("gridURL"));
        String desiredBrowserVersion = System.getProperty("desiredBrowserVersion");
        String desiredPlatform = System.getProperty("desiredPlatform");

        if (null != desiredPlatform && !desiredPlatform.isEmpty()) {
            desiredCapabilities.setPlatform(Platform.valueOf(desiredPlatform.toUpperCase()));
        }

        if (null != desiredBrowserVersion && !desiredBrowserVersion.isEmpty()) {
            desiredCapabilities.setVersion(desiredBrowserVersion);
        }

        desiredCapabilities.setBrowserName(selectedDriverType.toString());
        webDriver = new RemoteWebDriver(seleniumGridURL, desiredCapabilities);
    } else {
        webDriver = driverType.getWebDriverObject(desiredCapabilities);
    }
}
 
Example 4
Source File: BrowserRunnerHelper.java    From neodymium-library with MIT License 5 votes vote down vote up
public static Proxy createProxyCapabilities()
{
    final String proxyHost = Neodymium.configuration().getProxyHost() + ":" + Neodymium.configuration().getProxyPort();

    final Proxy webdriverProxy = new Proxy();
    webdriverProxy.setHttpProxy(proxyHost);
    webdriverProxy.setSslProxy(proxyHost);
    webdriverProxy.setFtpProxy(proxyHost);
    if (!StringUtils.isAllEmpty(Neodymium.configuration().getProxySocketUsername(), Neodymium.configuration().getProxySocketPassword())
        || Neodymium.configuration().getProxySocketVersion() != null)
    {
        webdriverProxy.setSocksProxy(proxyHost);
        if (StringUtils.isNoneEmpty(Neodymium.configuration().getProxySocketUsername(),
                                    Neodymium.configuration().getProxySocketPassword()))
        {
            webdriverProxy.setSocksUsername(Neodymium.configuration().getProxySocketUsername());
            webdriverProxy.setSocksPassword(Neodymium.configuration().getProxySocketPassword());
        }
        if (Neodymium.configuration().getProxySocketVersion() != null)
        {
            webdriverProxy.setSocksVersion(4);
        }
    }

    webdriverProxy.setNoProxy(Neodymium.configuration().getProxyBypass());
    return webdriverProxy;
}
 
Example 5
Source File: ExtensionSelenium.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private static void setCommonOptions(
        MutableCapabilities capabilities, String proxyAddress, int proxyPort) {
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    // W3C capability
    capabilities.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

    if (proxyAddress != null) {
        String httpProxy = proxyAddress + ":" + proxyPort;
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(httpProxy);
        proxy.setSslProxy(httpProxy);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }
}
 
Example 6
Source File: ProfileFactory.java    From Asqatasun with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setUpProxy(FirefoxProfile firefoxProfile) {
    if (!StringUtils.isEmpty(proxyPort) && !StringUtils.isEmpty(proxyHost)) {
        StringBuilder strb = new StringBuilder(proxyHost);
        strb.append(":");
        strb.append(proxyPort);
        Proxy proxy = new Proxy();
        proxy.setFtpProxy(strb.toString());
        proxy.setHttpProxy(strb.toString());
        proxy.setSslProxy(strb.toString());
        if (StringUtils.isNotEmpty(proxyExclusionUrl)) {
            proxy.setNoProxy(proxyExclusionUrl.replaceAll(";", ","));
        }
        firefoxProfile.setProxyPreferences(proxy);
    }
}
 
Example 7
Source File: ProxyServer.java    From odo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: Proxies.java    From JYTB with GNU General Public License v3.0 4 votes vote down vote up
public void setCurrentProxy(Datum currentProxy) {
    Proxy proxy = new Proxy();
    proxy.setHttpProxy(currentProxy.getIpPort());
    proxy.setSslProxy(currentProxy.getIpPort());
}
 
Example 9
Source File: Context.java    From NoraUi with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * @param clazz
 *            used to find class loader.
 * @throws TechnicalException
 *             is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
 */
public synchronized void initializeRobot(Class<?> clazz) throws TechnicalException {
    log.info("Context > initializeRobot() with {}", clazz.getCanonicalName());
    // set browser: chrome,firefox or ie
    browser = getProperty(BROWSER_KEY, applicationProperties);

    // set Webdriver file: src/test/resources/drivers/...
    initializeWebdriversProperties(Thread.currentThread().getContextClassLoader());

    // wait delay until web element is displayed.
    timeout = getIntProperty(TIMEOUT_KEY, applicationProperties);

    // set version of selectors used to deliver several versions
    selectorsVersion = getProperty(SELECTORS_VERSION, applicationProperties);

    // proxies configuration
    proxy = new Proxy();
    proxy.setAutodetect(true);
    final String httpProxy = getProperty(HTTP_PROXY, applicationProperties);
    if (httpProxy != null && !"".equals(httpProxy)) {
        proxy.setAutodetect(false);
        proxy.setHttpProxy(httpProxy);
    }

    final String httpsProxy = getProperty(HTTPS_PROXY, applicationProperties);
    if (httpsProxy != null && !"".equals(httpsProxy)) {
        proxy.setAutodetect(false);
        proxy.setSslProxy(httpsProxy);
    }

    final String noProxy = getProperty(NO_PROXY, applicationProperties);
    if (noProxy != null && !"".equals(noProxy)) {
        proxy.setAutodetect(false);
        proxy.setNoProxy(noProxy);
    }

    // OkHttp timeout
    connectTimeout = getIntProperty(OKHTTP_CONNECT_TIMEOUT, applicationProperties);
    writeTimeout = getIntProperty(OKHTTP_WRITE_TIMEOUT, applicationProperties);
    readTimeout = getIntProperty(OKHTTP_READ_TIMEOUT, applicationProperties);

    // authentication mode configuration
    Auth.setAuthenticationType(getProperty(AUTH_TYPE, applicationProperties));

    // set crypto key
    cryptoKey = System.getProperty(CRYPTO_KEY);
    if (cryptoKey == null) {
        log.warn("{} not set. You can not use crypto feature.", CRYPTO_KEY);
    }

    // stacktrace configuration
    displayStackTrace = "true".equals(getProperty(DISPLAY_STACK_TRACE, applicationProperties));

    // enable browser headless mode ?
    isHeadless = "true".equals(Context.getWebdriversProperties(HEADLESS));

    // init driver callbacks
    exceptionCallbacks.put(Callbacks.RESTART_WEB_DRIVER, STEPS_BROWSER_STEPS_CLASS_QUALIFIED_NAME, RESTART_WEB_DRIVER_METHOD_NAME);
    exceptionCallbacks.put(Callbacks.CLOSE_WINDOW_AND_SWITCH_TO_GITHUBAPI_HOME, STEPS_BROWSER_STEPS_CLASS_QUALIFIED_NAME, GO_TO_URL_METHOD_NAME, GITHUBAPI_HOME);
    exceptionCallbacks.put(Callbacks.CLOSE_WINDOW_AND_SWITCH_TO_BAKERY_HOME, STEPS_BROWSER_STEPS_CLASS_QUALIFIED_NAME, GO_TO_URL_METHOD_NAME, BAKERY_HOME);

    // init applications
    initApplicationDom(clazz.getClassLoader(), selectorsVersion, BAKERY_KEY);
    Application bakeryApp = new Application(BAKERY_HOME, getProperty(BAKERY_KEY, applicationProperties) + "/account/login");
    bakeryApp.addUrlPage(BAKERY_DEMO, getProperty(BAKERY_KEY, applicationProperties) + "/public");
    applications.put(BAKERY_KEY, bakeryApp);
    applications.put(GITHUBAPI_KEY, new Application(GITHUBAPI_HOME, getProperty(GITHUBAPI_KEY, applicationProperties)));

    // read and init all cucumber methods
    cucumberMethods = getAllCucumberMethods(clazz);
}