Example usage for org.openqa.selenium Proxy Proxy

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

Introduction

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

Prototype

public Proxy() 

Source Link

Usage

From source file:botski.selenium.SocialBot.java

License:Apache License

/**
 * Initialises Chrome as the default browser
 */// ww  w  .jav a2 s.  c o m
public void initializeChrome() {
    SeleniumUtils.setChromeDriver();
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    if (proxyHost != null) {
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(proxyHost + ":" + proxyPort);
        proxy.setHttpsProxy(proxyHost + ":" + proxyPort);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }
    browser = new ChromeDriver(capabilities);
    javascript = (JavascriptExecutor) browser;
    browser.manage().window().setSize(new Dimension(1024, 768));
}

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

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

    try {//from   w  w  w. j  a  v a 2s.c  o  m
        //            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 www  .  ja v a2  s  .  co  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.atanas.kanchev.testframework.selenium.driverfactory.DriverFactory.java

License:Apache License

private void configureProxy() {

    if (isProxyEnabled()) {
        proxy = new Proxy();
        proxy.setProxyType(MANUAL);//w  w  w .ja va  2  s.  com
        proxy.setHttpProxy(getProxyDetails());
        proxy.setSslProxy(getProxyDetails());

    }
}

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

License:Apache License

public void setCapabilities(AppiumMobilePlatformType platform, DesiredCapabilities capabilities)
        throws Exception {
    RunConfiguration config = getRunConfig();
    if (config.get(UiAutomator.MOBILE_PROXY).toLowerCase().equals("true")) {
        Proxy proxy = new Proxy();
        String p = config.get(UiAutomator.MOBILE_PROXY_HOST) + ":" + config.get(UiAutomator.MOBILE_PROXY_PORT);
        setHttpProxy(proxy, p);//  w  w  w  . j ava  2s .c  om
        setSslProxy(proxy, p);
        capabilities.setCapability("proxy", proxy);
    }
    switch (this.getContext()) {
    case MOBILE_WEB:
        setMobileWebCapabilities(platform, capabilities);
        break;
    case MOBILE_NATIVE:
        setMobileNativeCapabilities(platform, capabilities);
        break;
    default:
        throw new Exception("Unsupported automation context for Appium. Allowed: MOBILE_WEB/MOBILE_NATIVE");
    }
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public void setCapabilities(DesiredCapabilities capabilities) {
    RunConfiguration config = getRunConfig();
    if (config.get(UiAutomator.PC_BROWSER_PROXY).toLowerCase().equals("true")) {
        Proxy proxy = new Proxy();
        String p = config.get(UiAutomator.PC_BROWSER_PROXY_HOST) + ":"
                + config.get(UiAutomator.PC_BROWSER_PROXY_PORT);
        setHttpProxy(proxy, p);//w ww  .  j a  va2s .com
        setSslProxy(proxy, p);
        capabilities.setCapability("proxy", proxy);
    }
}

From source file:com.axatrikx.webdriver.ChromeLoader.java

License:Apache License

@Override
public WebDriver getDriver() {
    String resource = "chromedriver.exe";
    if (Utils.getOS().equals("Unix")) {
        resource = "chromedriver";
    }/*from w  ww.ja v  a 2s.c  o m*/
    System.setProperty("webdriver.chrome.driver", Utils.getResource(resource).getAbsolutePath());
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("disable-popup-blocking");
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("download.default_directory", downloadDir);
    prefs.put("profile.default_content_settings.popups", 0);

    // set chrome custom binary
    if (!chromeBinaryPath.isEmpty()) {
        prefs.put("binary", chromeBinaryPath);
    }

    chromeOptions.setExperimentalOption("prefs", prefs);

    if (useProxy) {
        String proxyURL = proxyHost + ":" + proxyPort;
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(proxyURL).setFtpProxy(proxyURL).setSslProxy(proxyURL);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }

    if (!chromeProfilePath.isEmpty()) {
        chromeOptions.addArguments("user-data-dir=" + chromeProfilePath);
    }

    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    return new ChromeDriver(capabilities);
}

From source file:com.axatrikx.webdriver.IELoader.java

License:Apache License

@Override
public WebDriver getDriver() {
    System.setProperty("webdriver.ie.driver", Utils.getResource("IEDriverServer.exe").getAbsolutePath());
    System.setProperty("java.io.tmpdir", downloadDir);
    DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    if (useProxy) {
        String proxyURL = proxyHost + ":" + proxyPort;
        Proxy proxy = new Proxy();
        proxy.setHttpProxy(proxyURL).setFtpProxy(proxyURL).setSslProxy(proxyURL);
        capabilities.setCapability(CapabilityType.PROXY, proxy);
    }// w  w w .  ja va2 s  .  co m
    return new InternetExplorerDriver(capabilities);
}

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

License:Apache License

public Proxy getProxy() {
    Proxy proxy = null;//w w w . j  a v a 2 s . co m
    if (proxyHost != null) {
        proxy = new Proxy();
        proxy.setProxyType(ProxyType.MANUAL);
        proxy.setHttpProxy(proxyHost);
        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   w w w.  j  a v  a 2 s.  com
    proxy.setSslProxy(proxyStr);

    return proxy;
}