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:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed

    try {/*from  w ww .  ja  v  a2  s.  com*/
        //            MarionetteDriverManager.getInstance().setup();
        System.out.println("Mulai Pencarian...");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;
        String kereta = ((ComboItem) comboKereta.getSelectedItem()).getValue();

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

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

            driver = new ChromeDriver(cap);
        } else {

            //                    driver = new MarionetteDriver();
            driver = new ChromeDriver();
        }
        //       hmin = Integer.valueOf(args[0]).intValue();
        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;
        boolean keeploop = true;
        while (/**list==null || list.size() == 0**/
        keeploop) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggal.getSelectedIndex());

                ComboItem stFrom = (ComboItem) comboStBerangkat.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(stFrom.getValue());

                ComboItem stTo = (ComboItem) comboStTujuan.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(stTo.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();
                //          Thread.sleep(1000);
                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                if (list != null && list.size() > 0) {
                    List<WebElement> listForm = driver.findElements(By.tagName("form"));
                    for (WebElement form : listForm) {
                        List<WebElement> listInput = form.findElements(By.tagName("input"));
                        for (WebElement input : listInput) {
                            if (input.getAttribute("value").equalsIgnoreCase(kereta)) {
                                WebElement btn = form.findElement(By.className("itButton"));
                                btn.click();
                                System.out.println("========================>KLIK BOOKING");
                                keeploop = false;
                                throw new KlikException("BerhasilKlik");
                            }
                        }
                    }
                }
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (KlikException ke) {
                System.out.println("================> Masuk Klik Exception");
                keeploop = false;
                break;
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }

        //       System.out.println("ada keretaaaaaa: "+list.size());
        List<WebElement> listInput = driver.findElements(By.tagName("input"));
        for (WebElement input : listInput) {
            if (input.getAttribute("type").equals("checkbox")) {
                input.click();
                break;
            }
        }
        WebElement lanjut = driver.findElement(By.cssSelector("input[type='submit'][name='booking']"));
        lanjut.click();

        //Ngisi Tikete 
        //Nunggu disit
        //tunggu sampe page ready, nandainnya kalo element div dengan css class "txt_first_name_adult_1" muncul
        WebElement elementForWait = (new WebDriverWait(driver, 3))
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("txt_first_name_adult_1")));
        //end wait
        WebElement namaPenumpang = driver.findElement(By.id("txt_first_name_adult_1"));
        WebElement ktp = driver.findElement(By.id("txt_passport_1"));

        WebElement contactName = driver.findElement(By.id("txt_contact_first_name"));
        WebElement contactEmail = driver.findElement(By.id("txt_contact_email"));
        WebElement contactPhone = driver.findElement(By.id("txt_contact_phone"));
        WebElement contactAddress = driver.findElement(By.id("txt_contact_home_address"));

        namaPenumpang.sendKeys(txtNamaPenumpang.getText());
        ktp.sendKeys(txtNoKTP.getText());
        contactName.sendKeys(txtNamaPenumpang.getText());
        contactEmail.sendKeys(txtEmail.getText());
        contactPhone.sendKeys(txtNoTelp.getText());
        contactAddress.sendKeys(txtAlamat.getText());

        playSound();

        JOptionPane.showMessageDialog(rootPane,
                "Booking sudah tersedia, Silakan inputkan Captcha!! Dan lanjutkan secara manual", "Informasi",
                JOptionPane.INFORMATION_MESSAGE);
        this.setAlwaysOnTop(true);

        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchBiasaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchBiasaActionPerformed

    try {/*from   w  w w  .j  a va  2s  .  c o  m*/
        Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

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

            driver = new ChromeDriver(cap);
        } else {
            driver = new ChromeDriver();
        }

        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;

        while (list == null || list.size() == 0) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggalBiasa.getSelectedIndex());

                ComboItem ck = (ComboItem) comboStBerangkatBiasa.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(ck.getValue());

                ComboItem ct = (ComboItem) comboStTujuanBiasa.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(ct.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();

                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (Exception e) {
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }
        System.out.println("ada keretaaaaaa: " + list.size());
        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public void setSslProxy(Proxy proxy, String proxyString) {
    proxy.setSslProxy(proxyString);
}

From source file:com.elastica.driver.DriverConfig.java

License:Apache License

public Proxy getProxy() {
    Proxy proxy = null;
    if (proxyHost != null) {
        proxy = new Proxy();
        proxy.setProxyType(ProxyType.MANUAL);
        proxy.setHttpProxy(proxyHost);//from w  ww  .  j av a2 s.com
        proxy.setFtpProxy(proxyHost);
        proxy.setSslProxy(proxyHost);
    }

    return proxy;

}

From source file:com.groupon.odo.bmp.ProxyServer.java

License:Apache License

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);//from  ww w  . j av  a  2  s.c  o m
    proxy.setSslProxy(proxyStr);

    return proxy;
}

From source file:com.qwazr.crawler.web.driver.BrowserDriverBuilder.java

License:Apache License

public BrowserDriver build() throws ReflectiveOperationException, SecurityException {
    BrowserDriverEnum browserType = BrowserDriverEnum.html_unit;

    final WebCrawlDefinition.ProxyDefinition proxyDef;

    DesiredCapabilities capabilities = null;

    if (crawlDefinition != null) {

        // Choose a browser type
        if (crawlDefinition.browser_type != null)
            browserType = crawlDefinition.browser_type;

        proxyDef = selectProxy();/*from   ww w  .j a  v  a2 s  .  c o m*/

        // Setup the proxy
        if (proxyDef != null) {
            capabilities = checkCapabilities(capabilities);
            org.openqa.selenium.Proxy proxy = new Proxy();
            if (proxyDef.http_proxy != null)
                proxy.setHttpProxy(proxyDef.http_proxy);
            if (proxyDef.ftp_proxy != null)
                proxy.setFtpProxy(proxyDef.ftp_proxy);
            if (proxyDef.ssl_proxy != null)
                proxy.setSslProxy(proxyDef.ssl_proxy);
            if (proxyDef.socks_proxy != null)
                proxy.setSocksProxy(proxyDef.socks_proxy);
            if (proxyDef.socks_username != null)
                proxy.setSocksUsername(proxyDef.socks_username);
            if (proxyDef.socks_password != null)
                proxy.setSocksPassword(proxyDef.socks_password);
            if (proxyDef.no_proxy != null)
                proxy.setNoProxy(proxyDef.no_proxy);
            if (proxyDef.proxy_autoconfig_url != null)
                proxy.setProxyAutoconfigUrl(proxyDef.proxy_autoconfig_url);
            capabilities.setCapability(CapabilityType.PROXY, proxy);
        }

        // Setup the language
        if (crawlDefinition.browser_language != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setCapability(AdditionalCapabilities.QWAZR_BROWSER_LANGUAGE,
                    crawlDefinition.browser_language);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(
                        PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language",
                        crawlDefinition.browser_language);
        }

        // Download images
        if (crawlDefinition.download_images != null) {
            capabilities = checkCapabilities(capabilities);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "loadImages",
                        crawlDefinition.download_images);
        }

        // Web security
        if (crawlDefinition.web_security != null) {
            capabilities = checkCapabilities(capabilities);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(
                        PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "webSecurityEnabled",
                        crawlDefinition.web_security);
        }

        // Choose a browser name
        if (crawlDefinition.browser_name != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setBrowserName(crawlDefinition.browser_name);
        }

        if (crawlDefinition.browser_version != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setVersion(crawlDefinition.browser_version);
        }

        // Javascript capability
        if (crawlDefinition.javascript_enabled != null) {
            capabilities = checkCapabilities(capabilities);
            capabilities.setJavascriptEnabled(crawlDefinition.javascript_enabled);
            if (browserType == BrowserDriverEnum.phantomjs)
                capabilities.setCapability(
                        PhantomJSDriverService.PHANTOMJS_PAGE_SETTINGS_PREFIX + "javascriptEnabled",
                        crawlDefinition.javascript_enabled);

        }

    } else
        proxyDef = null;

    if (browserType == BrowserDriverEnum.phantomjs) {
        capabilities = checkCapabilities(capabilities);
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,
                new String[] { "--webdriver-loglevel=NONE", "--ignore-ssl-errors=true" });
    }

    final WebDriver driver = browserType.getNewInstance(capabilities);
    try {
        final BrowserDriver browserDriver = new BrowserDriver(browserType, driver, proxyDef);
        browserDriver.setTimeouts(crawlDefinition.implicitly_wait, crawlDefinition.page_load_timeout,
                crawlDefinition.script_timeout);

        if (crawlDefinition.cookies != null)
            for (Map.Entry<String, String> cookie : crawlDefinition.cookies.entrySet())
                driver.manage().addCookie(new Cookie(cookie.getKey(), cookie.getValue()));

        return browserDriver;
    } catch (Exception e) {
        driver.quit();
        throw e;
    }
}

From source file:de.ppi.selenium.browser.DefaultWebDriverFactory.java

License:Apache License

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

    ClientProperties properties = new ClientProperties(options.get(CLIENT_PROPERTIES_KEY));

    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");
        }//w  w  w . j  a  va 2  s.  c om
        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.operaBlink();
        } 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 if (browser.equalsIgnoreCase("phantomjs")) {
            capabilities = DesiredCapabilities.phantomjs();
        } 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) {
            LOG.warn("error getting the computer-name", e);
        }

        capabilities.setCapability("name",
                "WebBrowser 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", Integer.valueOf(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:io.kahu.hawaii.cucumber.glue.html.HtmlSteps.java

License:Apache License

private Proxy getHttpProxy() {
    Proxy proxy = null;
    String proxyHost = System.getProperty(PROXY_HOST_KEY);
    String proxyPort = System.getProperty(PROXY_PORT_KEY);
    if (proxyHost != null && proxyPort != null) {
        proxy = new Proxy();
        proxy.setHttpProxy(proxyHost + ":" + proxyPort);
        proxy.setProxyType(Proxy.ProxyType.MANUAL);
        proxy.setSslProxy(proxyHost + ":" + proxyPort);
    }//from w  w  w  . j  av a 2s . c  o  m
    return proxy;
}

From source file:net.continuumsecurity.web.drivers.BurpFirefoxDriver.java

License:Open Source License

public Proxy getBurpProxy() {
    Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.MANUAL);
    String proxyStr = String.format("%s:%d", Config.getBurpHost(), Config.getBurpPort());
    proxy.setHttpProxy(proxyStr);//from   w ww  . j a  v a  2 s.co  m
    proxy.setSslProxy(proxyStr);

    return proxy;
}

From source file:net.continuumsecurity.web.drivers.DriverFactory.java

License:Open Source License

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