Example usage for org.openqa.selenium Proxy setSslProxy

List of usage examples for org.openqa.selenium Proxy setSslProxy

Introduction

In this page you can find the example usage for org.openqa.selenium Proxy setSslProxy.

Prototype

public Proxy setSslProxy(String sslProxy) 

Source Link

Document

Specify which proxy to use for SSL connections.

Usage

From source file:org.asqatasun.sebuilder.tools.ProfileFactory.java

License:Open Source License

private void setUpProxy(FirefoxProfile firefoxProfile) {
    if (!StringUtils.isEmpty(proxyPort) && !StringUtils.isEmpty(proxyHost)) {
        StringBuilder strb = new StringBuilder(proxyHost);
        strb.append(":");
        strb.append(proxyPort);//from   w  w w. j  a  v  a2s .  c  o m
        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);
    }
}

From source file:org.finra.jtaf.ewd.impl.DefaultSessionFactory.java

License:Apache License

@Override
public DesiredCapabilities createCapabilities(Map<String, String> options) throws Exception {

    ClientProperties properties = new ClientProperties(options.get("client"));

    final String browser = properties.getBrowser();

    if (properties.isUseGrid()) {
        DesiredCapabilities capabilities = null;

        if (properties.getGridUrl().length() == 0) {
            throw new Exception("You must provide 'grid.url' to use Selenium Grid in client property file");
        }//from w ww . j  a va 2s.  c o m
        if (browser.length() == 0) {
            throw new Exception("You must provide 'browser' to use Selenium Grid  in client property file");
        }
        if (properties.getGridPlatform().length() == 0) {
            throw new Exception(
                    "You must provide 'grid.platform' to use Selenium Grid in client property file");
        }

        if (browser.equalsIgnoreCase("ie") || browser.equalsIgnoreCase("iexplore")
                || browser.equalsIgnoreCase("*iexplore")) {
            capabilities = DesiredCapabilities.internetExplorer();
        } else if ((browser.equalsIgnoreCase("firefox") || browser.equalsIgnoreCase("*firefox"))) {
            capabilities = DesiredCapabilities.firefox();
        } else if (browser.equalsIgnoreCase("chrome")) {
            capabilities = DesiredCapabilities.chrome();
        } else if (browser.equalsIgnoreCase("safari")) {
            capabilities = DesiredCapabilities.safari();
        } else if (browser.equalsIgnoreCase("opera")) {
            capabilities = DesiredCapabilities.opera();
        } else if (browser.equalsIgnoreCase("android")) {
            capabilities = DesiredCapabilities.android();
        } else if (browser.equalsIgnoreCase("ipad")) {
            capabilities = DesiredCapabilities.ipad();
        } else if (browser.equalsIgnoreCase("iphone")) {
            capabilities = DesiredCapabilities.iphone();
        } else {
            log.fatal("Unsupported browser: " + browser
                    + " Please refer to documentation for supported browsers.");
        }

        capabilities.setVersion(properties.getBrowserVersion());

        String platform = properties.getGridPlatform();
        if (platform != null && platform.length() > 0) {
            capabilities.setCapability("platform", platform);
        } else {
            // Default to Windows 7
            capabilities.setCapability("platform", "Windows 7");
        }

        // Set Proxy
        String proxyStr = properties.getProxy();
        String proxyHttps = properties.getProxyHttps();
        Proxy proxy = null;
        if (proxyStr != null && !proxyStr.equals("")) {
            proxy = new Proxy();
            proxy.setHttpProxy(proxyStr);

        }
        if (proxyHttps != null && !proxyHttps.equals("")) {
            if (proxy == null) {
                proxy = new Proxy();
            }
            proxy.setSslProxy(proxyHttps);
        }

        if (proxy != null) {
            capabilities.setCapability(CapabilityType.PROXY, proxy);
        }

        // preparing data for session name
        String computerName = null;
        try {
            computerName = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
        }

        capabilities.setCapability("name",
                "JTAF EWD client=" + properties.getClient() + "; started from " + computerName);

        String gridProperties = properties.getGridProperties();
        if (gridProperties != null && gridProperties.length() > 0) {
            String[] gridPropertiesSlpitted = gridProperties.split(" ");
            for (String gridPropertiesSlpittedCurrent : gridPropertiesSlpitted) {
                if (gridPropertiesSlpittedCurrent != null && gridPropertiesSlpittedCurrent.length() > 0) {
                    String[] propertyNameAndValue = gridPropertiesSlpittedCurrent.split("=");
                    if (propertyNameAndValue.length == 2) {
                        capabilities.setCapability(propertyNameAndValue[0], propertyNameAndValue[1]);
                    }
                }
            }
        }

        return capabilities;
    } else {
        log.debug("browser [" + browser + "]");

        // Turning off all console logs using java.util.logging
        Handler[] h = java.util.logging.LogManager.getLogManager().getLogger("").getHandlers();
        for (int i = 0; i < h.length; i++) {
            if (h[i] instanceof ConsoleHandler) {
                h[i].setLevel(Level.OFF);
            }
        }

        String proxyProperty = properties.getProxy();
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        if (proxyProperty != null) {
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyProperty).setFtpProxy(proxyProperty).setSslProxy(proxyProperty);
            desiredCapabilities = new DesiredCapabilities();
            if (browser != null && browser.equalsIgnoreCase("chrome")) {
                // chrome way of proxy initialization
                desiredCapabilities.setCapability("chrome.switches",
                        Arrays.asList("--proxy-server=http://" + proxy));
            } else {
                // ff and ie way of proxy initialization
                desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
            }
        }

        if (properties.getDownloadFolder() != null && properties.getDownloadFolder().length() > 0) {
            // '0' means to download to the desktop, '1' means to download
            // to the default "Downloads" directory, '2' means to use the
            // directory you specify in "browser.download.dir"
            desiredCapabilities.setCapability("browser.download.folderList", 2);
            desiredCapabilities.setCapability("browser.download.dir", System.getProperty("user.dir")
                    + System.getProperty("file.separator") + properties.getDownloadFolder());
            desiredCapabilities.setCapability("browser.helperApps.neverAsk.saveToDisk",
                    "text/csv, application/octet-stream, application/pdf, application/vnd.fdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
            desiredCapabilities.setCapability("browser.helperApps.alwaysAsk.force", false);
            desiredCapabilities.setCapability("browser.download.manager.showWhenStarting", false);
        }
        return desiredCapabilities;
    }
}

From source file:org.mozilla.zest.core.v1.ZestClientLaunch.java

License:Mozilla Public License

@Override
public String invoke(ZestRuntime runtime) throws ZestClientFailException {

    try {//from  w w  w .j  ava  2  s .c  o m
        WebDriver driver = null;
        DesiredCapabilities cap = new DesiredCapabilities();

        String httpProxy = runtime.getProxy();
        if (httpProxy.length() > 0) {
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(httpProxy);
            proxy.setSslProxy(httpProxy);
            cap.setCapability(CapabilityType.PROXY, proxy);
        }
        if (capabilities != null) {
            for (String capability : capabilities.split("\n")) {
                if (capability != null && capability.trim().length() > 0) {
                    String[] typeValue = capability.split("=");
                    if (typeValue.length != 2) {
                        throw new ZestClientFailException(this,
                                "Invalid capability, expected type=value : " + capability);
                    }
                    cap.setCapability(typeValue[0], typeValue[1]);
                }
            }
        }

        if ("Firefox".equalsIgnoreCase(this.browserType)) {
            driver = new FirefoxDriver(cap);
        } else if ("Chrome".equalsIgnoreCase(this.browserType)) {
            driver = new ChromeDriver(cap);
        } else if ("HtmlUnit".equalsIgnoreCase(this.browserType)) {
            driver = new HtmlUnitDriver(DesiredCapabilities.htmlUnit().merge(cap));
        } else if ("InternetExplorer".equalsIgnoreCase(this.browserType)) {
            driver = new InternetExplorerDriver(cap);
        } else if ("Opera".equalsIgnoreCase(this.browserType)) {
            driver = new OperaDriver(cap);
        } else if ("PhantomJS".equalsIgnoreCase(this.browserType)) {
            driver = new PhantomJSDriver(cap);
        } else if ("Safari".equalsIgnoreCase(this.browserType)) {
            driver = new SafariDriver(cap);
        } else {
            // See if its a class name
            try {
                Class<?> browserClass = this.getClass().getClassLoader().loadClass(this.browserType);
                Constructor<?> cons = browserClass.getConstructor(Capabilities.class);
                if (cons != null) {
                    driver = (WebDriver) cons.newInstance(cap);
                } else {
                    throw new ZestClientFailException(this,
                            "Unsupported browser type: " + this.getBrowserType());
                }
            } catch (ClassNotFoundException e) {
                throw new ZestClientFailException(this, "Unsupported browser type: " + this.getBrowserType());
            }
        }

        runtime.addWebDriver(getWindowHandle(), driver);

        if (this.url != null) {
            driver.get(runtime.replaceVariablesInString(this.url, true));
        }

        return getWindowHandle();

    } catch (Exception e) {
        throw new ZestClientFailException(this, e);
    }
}

From source file:org.paxml.selenium.webdriver.NewSessionTag.java

License:Open Source License

private WebDriver createWebDriver(Context context) {
    Proxy proxy = new Proxy();
    if (StringUtils.isNotBlank(proxyHttp)) {
        proxy.setHttpProxy(proxyHttp);//from  www .  j  a v  a  2s.  com
    }
    if (StringUtils.isNotBlank(proxyFtp)) {
        proxy.setFtpProxy(proxyFtp);
    }
    if (StringUtils.isNotBlank(proxySsl)) {
        proxy.setSslProxy(proxySsl);
    }
    if (StringUtils.isNotBlank(proxyAutoConfigUrl)) {
        proxy.setProxyAutoconfigUrl(proxyAutoConfigUrl);
    }
    if (proxyAutoDetect != null) {
        proxy.setAutodetect(proxyAutoDetect);
    }

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.PROXY, proxy);
    cap.setJavascriptEnabled(true);

    if (StringUtils.isNotBlank(hub)) {
        final URL url;
        try {
            url = new URL(hub);
        } catch (MalformedURLException e) {
            throw new RuntimeException("hub url is invalid: " + hub, e);
        }
        if ("firefox".equalsIgnoreCase(browser)) {
            cap = cap.firefox();
        } else if ("iexplore".equalsIgnoreCase(browser)) {
            cap = cap.internetExplorer();
        } else if ("chrome".equalsIgnoreCase(browser)) {
            cap = cap.chrome();
        }
        return new RemoteWebDriver(url, cap);
    }

    if ("firefox".equalsIgnoreCase(browser)) {
        return new FirefoxDriver(cap);
    }
    if ("iexplore".equalsIgnoreCase(browser)) {
        return new InternetExplorerDriver(cap);
    }
    if ("chrome".equalsIgnoreCase(browser)) {
        return new ChromeDriver(cap);
    }

    throw new RuntimeException("unknown browser type: " + browser);

}

From source file:org.securitytests.cisecurity.drivers.DriverFactory.java

License:Open Source License

public DesiredCapabilities createProxyCapabilities() {
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    Proxy proxy = new Proxy();
    proxy.setHttpProxy(Config.getProxyHost() + ":" + Config.getProxyPort());
    proxy.setSslProxy(Config.getProxyHost() + ":" + Config.getProxyPort());
    capabilities.setCapability("proxy", proxy);
    return capabilities;
}

From source file:org.zaproxy.zap.extension.selenium.ExtensionSelenium.java

License:Apache License

private static WebDriver getWebDriverImpl(Browser browser, String proxyAddress, int proxyPort) {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    if (proxyAddress != null) {
        String httpProxy = proxyAddress + ":" + proxyPort;
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(httpProxy);/*from   ww  w.  j a v  a2  s  . c  o  m*/
        proxy.setSslProxy(httpProxy);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }

    switch (browser) {
    case CHROME:
        return new ChromeDriver(capabilities);
    case FIREFOX:
        return new FirefoxDriver(capabilities);
    case HTML_UNIT:
        return new HtmlUnitDriver(capabilities);
    case INTERNET_EXPLORER:
        capabilities.setCapability(InternetExplorerDriver.IE_USE_PRE_PROCESS_PROXY, true);

        return new InternetExplorerDriver(capabilities);
    /* No longer supported in the Selenium standalone jar
     * need to decide if we support older Opera versions 
    case OPERA:
    OperaDriver driver = new OperaDriver(capabilities);
    if (proxyAddress != null) {
        driver.proxy().setProxyLocal(true);
        // XXX Workaround, in operadriver <= 1.5 the HTTPS proxy settings are not set according to desired capabilities
        // For more details see OperaProxy.parse(Proxy)
        driver.proxy().setHttpsProxy(proxyAddress + ":" + proxyPort);
    }
            
    return driver;
    */
    case PHANTOM_JS:
        final ArrayList<String> cliArgs = new ArrayList<>(4);
        cliArgs.add("--ssl-protocol=any");
        cliArgs.add("--ignore-ssl-errors=yes");

        cliArgs.add("--webdriver-logfile=" + Constant.getZapHome() + "/phantomjsdriver.log");
        cliArgs.add("--webdriver-loglevel=WARN");

        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgs);

        return new PhantomJSDriver(capabilities);
    case SAFARI:
        return new SafariDriver(capabilities);
    default:
        throw new IllegalArgumentException("Unknown browser: " + browser);
    }
}