Example usage for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile

List of usage examples for org.openqa.selenium.firefox FirefoxProfile FirefoxProfile

Introduction

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

Prototype

public FirefoxProfile() 

Source Link

Usage

From source file:com.ceiwc.compugain.setup.TestBase.java

public WebDriver secondDriverInitialization(String sbrowser/*,String surl*/) {

    sbrowser = Configuration.getAutomationBrowser();
    logger.info("Browser Name:" + sbrowser);
    //   logger.info(" Application surl:"+surl);
    if (secondDriver == null) {
        if (sbrowser.equalsIgnoreCase("firefox")) {
            String downloadPath = FileOperation.getFilePath(DOWNLOADSPATH);
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.dir", downloadPath);
            profile.setPreference("browser.helperApps.neverAsk.openFile",
                    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            profile.setPreference("browser.download.manager.focusWhenStarting", false);
            profile.setPreference("browser.download.manager.useWindow", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", false);
            profile.setPreference("xpinstall.signatures.required", false);
            logger.info("The Profile Setup Data");
            secondDriver = new FirefoxDriver(profile);
            //secondDriver = new FirefoxDriver(firefoxProfileSetUp());
            /* webdriver= new EventFiringWebDriver(driver);
             EventListerners eventListerners=new EventListerners();
             webdriver.register(eventListerners);
            *//* w  w  w.j a  v  a  2s  .  com*/
        } else if (sbrowser.equalsIgnoreCase("Chrome")) {
            /*System.setProperty("webdriver.chrome.driver", getFilePath(CHROMEPATH));
            HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("profile.default_content_settings.popups", 0);
            chromePrefs.put("download.default_directory",getFilePath(DOWNLOADSPATH));
            ChromeOptions options = new ChromeOptions();
            HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
            options.setExperimentalOption("prefs", chromePrefs);
            options.addArguments("--test-type");
            DesiredCapabilities cap = DesiredCapabilities.chrome();
            cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
            cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            cap.setCapability(ChromeOptions.CAPABILITY, options);
            */ secondDriver = new ChromeDriver(chromeProfileSetUp());
            //secondDriver = new ChromeDriver(chromeProfileSetUp());
            /*    webdriver= new EventFiringWebDriver(driver);
                EventListerners eventListerners=new EventListerners();
                webdriver.register(eventListerners);
            */ } else if (sbrowser.equalsIgnoreCase("IE")) {
            /*if (System.getProperty("os.arch").contains("86")) {
            logger.info("System is---"+System.getProperty("os.arch")+"---bit");
              System.setProperty("webdriver.ie.driver",
            getFilePath("/src/test/resources/Browsers_Binaries/IE/IEDriverServer64.exe"));
             } 
            else if (System.getProperty("os.arch").contains("64")) {
               logger.info("System is---"+System.getProperty("os.arch")+"---bit");
              System.setProperty("webdriver.ie.driver",
            getFilePath("/src/test/resources/Browsers_Binaries/IE/IEDriverServer64.exe"));
            }*/
            secondDriver = new InternetExplorerDriver(ieProfileSetUp());
            /*webdriver= new EventFiringWebDriver(driver);
            EventListerners eventListerners=new EventListerners();
            webdriver.register(eventListerners);
            */} else if (sbrowser.equalsIgnoreCase("Safari")) {
            DesiredCapabilities capabilities = DesiredCapabilities.safari();
            secondDriver = new SafariDriver(capabilities);
            /*    webdriver= new EventFiringWebDriver(driver);
                EventListerners eventListerners=new EventListerners();
                webdriver.register(eventListerners);
            */}

    }
    secondDriver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
    return secondDriver;
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public WebDriver thirdDriverInitialization(String sbrowser/*,String surl*/) {
    sbrowser = Configuration.getAutomationBrowser();
    logger.info("Browser Name:" + sbrowser);
    //   logger.info(" Application surl:"+surl);
    if (thirdDriver == null) {
        if (sbrowser.equalsIgnoreCase("firefox")) {
            String downloadPath = FileOperation.getFilePath(DOWNLOADSPATH);
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.dir", downloadPath);
            profile.setPreference("browser.helperApps.neverAsk.openFile",
                    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            profile.setPreference("browser.download.manager.focusWhenStarting", false);
            profile.setPreference("browser.download.manager.useWindow", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", false);
            profile.setPreference("xpinstall.signatures.required", false);
            logger.info("The Profile Setup Data");
            thirdDriver = new FirefoxDriver(profile);

            //thirdDriver = new FirefoxDriver(firefoxProfileSetUp());
            /*    webdriver= new EventFiringWebDriver(driver);
                EventListerners eventListerners=new EventListerners();
                webdriver.register(eventListerners);
            */} else if (sbrowser.equalsIgnoreCase("Chrome")) {
            thirdDriver = new ChromeDriver(chromeProfileSetUp());
        } else if (sbrowser.equalsIgnoreCase("IE")) {
            thirdDriver = new InternetExplorerDriver(ieProfileSetUp());
        } else if (sbrowser.equalsIgnoreCase("Safari")) {
            DesiredCapabilities capabilities = DesiredCapabilities.safari();
            thirdDriver = new SafariDriver(capabilities);
        }//  w w w  .  ja  v  a 2 s.c om

    }
    thirdDriver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
    return thirdDriver;
    //return webdriver;
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public WebDriver driverIntialization(String sbrowser) {
    WebDriver fourthdriver = null;/* w  w  w  . j a v a  2  s . c  o m*/
    sbrowser = Configuration.getAutomationBrowser();
    logger.info("Browser Name:" + sbrowser);
    if (fourthdriver == null) {
        if (sbrowser.equalsIgnoreCase("firefox")) {
            String downloadPath = FileOperation.getFilePath(DOWNLOADSPATH);
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.dir", downloadPath);
            profile.setPreference("browser.helperApps.neverAsk.openFile",
                    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            profile.setPreference("browser.download.manager.focusWhenStarting", false);
            profile.setPreference("browser.download.manager.useWindow", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", false);
            profile.setPreference("xpinstall.signatures.required", false);
            logger.info("The Profile Setup Data");
            fourthdriver = new FirefoxDriver(profile);
        } else if (sbrowser.equalsIgnoreCase("Chrome")) {
            fourthdriver = new ChromeDriver(chromeProfileSetUp());
        } else if (sbrowser.equalsIgnoreCase("IE")) {
            fourthdriver = new InternetExplorerDriver(ieProfileSetUp());
        } else if (sbrowser.equalsIgnoreCase("Safari")) {
            DesiredCapabilities capabilities = DesiredCapabilities.safari();
            fourthdriver = new SafariDriver(capabilities);
        }

    }
    fourthdriver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
    return fourthdriver;
}

From source file:com.ceiwc.compugain.setup.TestBase.java

public FirefoxProfile firefoxProfileSetUp() {
    FirefoxProfile profile = new FirefoxProfile();
    String downloadFilepath = getFilePath(DOWNLOADSPATH);
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.manager.showWhenStarting", false);
    profile.setPreference("browser.download.dir", downloadFilepath);
    profile.setPreference("browser.helperApps.neverAsk.openFile",
            "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
    profile.setPreference("browser.helperApps.alwaysAsk.force", false);
    profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    profile.setPreference("browser.download.manager.focusWhenStarting", false);
    profile.setPreference("browser.download.manager.useWindow", false);
    profile.setPreference("browser.download.manager.showAlertOnComplete", false);
    profile.setPreference("browser.download.manager.closeWhenDone", false);
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
            "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
    logger.info("Profile Setup done for firefox");
    return profile;
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build a webDriver based on the passed in browser request
 *
 * @param browser//from  w ww . ja  v  a  2  s. c  o  m
 * @return WebDriver
 * @throws MalformedURLException
 */
private static WebDriver buildWebDriver(String browserName) {
    DesiredCapabilities capability = null;
    BrowserType browserType = BrowserType.getBrowserTypeFromString(browserName);
    switch (browserType) {
    case MARIONETTE:
        FirefoxProfile ffProfile = null;
        ffProfile = new FirefoxProfile();
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        cap.setCapability("firefox_profile", ffProfile);
        cap.setCapability("handlesAlerts", true);
        sysEnv = System.getenv("webdriver.firefox.marionette");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "geckodriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.firefox.marionette in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.firefox.marionette", sysEnv);
            }
        }
        return new MarionetteDriver(capability);
    case FIREFOX_DRIVER:
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        firefoxProfile.setAssumeUntrustedCertificateIssuer(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        return new FirefoxDriver(capability);
    case CHROME_DRIVER:
        sysEnv = System.getenv("webdriver.chrome.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "chromedriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.chrome.driver in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.chrome.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments(new String[] { "--allow-running-insecure-content" });
        options.addArguments(new String[] { "--ignore-certificate-errors" });
        options.addArguments(new String[] { "--enable-npapi" });
        options.addArguments(new String[] { "--disable-extensions" });
        options.addArguments(new String[] { "--start-maximized" });
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability(ChromeOptions.CAPABILITY, options);
        return new ChromeDriver(capability);
    case INTERNET_EXPLORER:
        sysEnv = System.getenv("webdriver.ie.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "IEDriverServer.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.ie.driver in system environment variables and restart the PC");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.ie.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.internetExplorer();
        capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        capability.setCapability("ignoreProtectedModeSettings", true);
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability("ignoreZoomSetting", true);
        capability.setCapability("nativeEvents", true);
        capability.setCapability("ie.ensureCleanSession", true);
        return new InternetExplorerDriver(capability);
    case SAFARI:
        capability = DesiredCapabilities.safari();
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ensureCleanSession", true);
        capability.setJavascriptEnabled(true);
        return new SafariDriver(capability);
    /*        case OPERA_DRIVER:
    capability = DesiredCapabilities.opera();
    capability.setCapability("opera.host", "127.0.0.1");
    return new OperaDriver();
     */
    case EDGE:
        capability = DesiredCapabilities.edge();
        EdgeOptions option = new EdgeOptions();
        capability.setCapability("edgeOptions", option);
        return new EdgeDriver(capability);
    default:
        log.info(
                "Currenty support is there for Chrome, Firefox, Firefox Marionette, Internet Explorer, Edge, Safari & Opera. Support is not there for "
                        + browserName);
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProf = new FirefoxProfile();
        firefoxProf.setAcceptUntrustedCertificates(true);
        firefoxProf.setEnableNativeEvents(true);
        firefoxProf.setAssumeUntrustedCertificateIssuer(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProf);
        return new FirefoxDriver(capability);
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build a RemoteWebDriver based on the passed in browser request
 *
 * @param browser//from  w  w  w . j  a v a  2s .c  o m
 * @return RemoteWebDriver
 *
 */
private static RemoteWebDriver buildRemoteWebDriver(String browserName) {
    DesiredCapabilities capability = null;
    BrowserType browserType = BrowserType.getBrowserTypeFromString(browserName);
    switch (browserType) {
    case MARIONETTE:
        FirefoxProfile ffProfile = null;
        ffProfile = new FirefoxProfile();
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        cap.setCapability("firefox_profile", ffProfile);
        cap.setCapability("handlesAlerts", true);
        sysEnv = System.getenv("webdriver.firefox.marionette");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "geckodriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.firefox.marionette in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.firefox.marionette", sysEnv);
            }
        }
        return new MarionetteDriver(capability);
    case FIREFOX_DRIVER:
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new FirefoxDriver(capability);
    case CHROME_DRIVER:
        sysEnv = System.getenv("webdriver.chrome.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "chromedriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.chrome.driver in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.chrome.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments(new String[] { "--allow-running-insecure-content" });
        options.addArguments(new String[] { "--ignore-certificate-errors" });
        options.addArguments(new String[] { "--enable-npapi" });
        options.addArguments(new String[] { "--disable-extensions" });
        options.addArguments(new String[] { "--start-maximized" });
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability(ChromeOptions.CAPABILITY, options);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new ChromeDriver(capability);
    case INTERNET_EXPLORER:
        sysEnv = System.getenv("webdriver.ie.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "IEDriverServer.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.ie.driver in system environment variables and restart the PC");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.ie.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.internetExplorer();
        capability.setCapability("ignoreProtectedModeSettings", true);
        String browserVersion = capability.getVersion();
        if (browserVersion != null && browserVersion.equals("10")) {
            capability.setPlatform(Platform.WINDOWS);
            capability.setVersion(browserVersion);
        } else if (browserVersion != null && browserVersion.equals("11")) {
            capability.setPlatform(Platform.WIN8_1);
            capability.setVersion(browserVersion);
        }
        capability.setBrowserName("internet explorer");
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new InternetExplorerDriver(capability);
    case SAFARI:
        capability = DesiredCapabilities.safari();
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ensureCleanSession", true);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(null);
        return new SafariDriver(capability);
    /*         case OPERA_DRIVER:
    capability = DesiredCapabilities.opera();
    capability.setCapability("opera.profile", "/test");
    return new OperaDriver();
    */
    case EDGE:
        capability = DesiredCapabilities.edge();
        EdgeOptions option = new EdgeOptions();
        capability.setCapability("edgeOptions", option);
        return new EdgeDriver(capability);
    default:
        log.info(
                "Currenty support is there for Chrome, Firefox, Firefox Marionette, Internet Explorer, Edge, Safari & Opera. Support is not there for "
                        + browserName);
        capability = DesiredCapabilities.firefox();
        firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new FirefoxDriver(capability);
    }
}

From source file:com.cisco.dbds.utils.selenium.SeleniumUtilities.java

License:Open Source License

/**
 * Opens the Firefox instance for Selenium.
 *//*w w w .ja  v  a 2  s .  c  om*/
public static void openBrowser() {
    try {
        String browser = Validate.readsystemvariable("browser");
        LogHandler.info("Browser:" + browser);

        String digest = Validate.readsystemvariable("browser.digest");
        LogHandler.info("Digest Auth:" + digest);

        if (browser.equals("firefox") && digest.toUpperCase().equals("YES")) {
            LogHandler.info("Fire Fox Driver with addon configuration");
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.link.open_newwindow", 2);
            File extentions = new File(
                    System.getProperty("user.dir") + Validate.readsystemvariable("firefox.addons.path"));
            if (extentions.exists()) {
                for (File extention : extentions.listFiles()) {
                    if (extention.getName().endsWith(".xpi")) {
                        try {
                            profile.addExtension(new File(extention.getAbsolutePath()));
                        } catch (IOException e) {
                            Assert.assertTrue("Exception occured while adding the extension to the profile..",
                                    false);
                        }
                        LogHandler.info("Added extention: " + extention.getName());
                    }
                }
            }
            driver = new FirefoxDriver(profile);
        } else if (browser.equals("firefox") && digest.toUpperCase().equals("NO")) {
            LogHandler.info("Fire Fox Driver without addon configuration");
            driver = new FirefoxDriver();
        } else if (browser.equals("chrome"))

        {
            LogHandler.info("Chrome Driver configuration");
            JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class);
            jarfilehandler.copyResourcesToDirectory(jarFile, "chrome", "src/it/resources/chrome");
            System.setProperty("webdriver.chrome.driver", "src/it/resources/chrome/chromedriver.exe");
            driver = new ChromeDriver();

        } else if (browser.equals("IE")) {

            LogHandler.info("IE Driver configuration");
            DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
            String IEpath = (SeleniumUtilities.class).getResource("").getPath();
            System.out.println(IEpath.substring(0, IEpath.length() - 31));

            capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                    true);
            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

            JarFile jarFile = jarfilehandler.jarForClass(SeleniumUtilities.class);
            // JarFile jarFile = new
            // JarFile("C:\\Users\\amsathishkumar\\.m2\\repository\\com\\cisco\\dbds\\Utils\\0.0.1-Release\\Utils-0.0.1-Release.jar");
            jarfilehandler.copyResourcesToDirectory(jarFile, "internetexplorer",
                    "src/it/resources/InternetExplorer");

            System.setProperty("webdriver.ie.driver", "src/it/resources/internetexplorer/IEDriverServer.exe");
            driver = new InternetExplorerDriver(capabilities);

            // driver = new InternetExplorerDriver();
        } else {
            Assert.assertTrue("include the browswer variable...", false);
        }
    } catch (Exception e) {
        LogHandler.info("Check the varaiables: browser,firefox.addons.path,user.dir");

    }
    //   driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);
    //   driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(Integer.parseInt(System.getProperty("implicit.wait")),
            TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(Integer.parseInt(System.getProperty("explicit.wait")),
            TimeUnit.SECONDS);
}

From source file:com.citrix.g2w.webdriver.tests.BaseWebDriverTest.java

License:Open Source License

/**
 * Method to create new WebDriver by setting desired browser language.
 * //w  ww.ja  v  a2 s  .c om
 * @param browserLanguage
 *            (browser language)
 * @return (driver object depends on input)
 */
protected WebDriver getWebDriverBySettingDesiredBrowserLanguage(final String browserLanguage) {
    String driver = this.propertyUtil.getProperty("driver");
    if ((driver != null) && (driver.equalsIgnoreCase("firefox"))) {
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("intl.accept_languages", browserLanguage);
        return new FirefoxDriver(profile);
    } else {
        BrowserVersion browserVersion = new BrowserVersion("null", "null", "null", 0);
        browserVersion.setBrowserLanguage(browserLanguage);
        return new HtmlUnitDriver(browserVersion);
    }
}

From source file:com.cognifide.aet.worker.drivers.FirefoxProfileBuilder.java

License:Apache License

private FirefoxProfileBuilder() {
    firefoxProfile = new FirefoxProfile();
}

From source file:com.coinbot.core.Worker.java

License:Open Source License

@Override
public void run() {
    File pathToBinary = new File("/home/jian/Descargas/firefox46/bin/firefox");
    // Firefox 46 needed
    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
    FirefoxProfile profile = new FirefoxProfile();
    FirefoxDriver driver = new FirefoxDriver(ffBinary, profile);
    CoinbotApplication.ui.workerQueue.addWorker(workerPanel);

    while (CoinbotApplication.bot.isRunning()) {
        // Sacamos un "claim" de la cola
        Claim claim = CoinbotApplication.bot.getClaimQueue().next();
        if (claim == null) {
            continue;
        }/*from  w w w  .ja va  2s .  c o m*/

        claim.getPanel().reset();
        claim.getPanel().getProgressBar().setMaximum(10);
        workerPanel.addClaim(claim.getPanel());
        claim.getPanel().nextStep("Opening URL");

        try {
            driver.manage().timeouts().pageLoadTimeout(12, TimeUnit.SECONDS);
            driver.navigate().to(new URL(claim.getFaucet().getUrl()));
        } catch (MalformedURLException e) {
            e.printStackTrace();
            continue;
        } catch (TimeoutException e) {
            // Busca un elemento, si no lo encuentra que vuelva a cargar
            e.printStackTrace();
        }

        // Detectando captcha
        claim.getPanel().nextStep("Detecting Captcha");
        CaptchaDetector captchaDetector = new CaptchaDetector();
        CaptchaService captcha = null;

        try {
            captcha = captchaDetector.find(driver, driver.findElement(By.tagName("body")));
        } catch (NoSuchElementException ex) {
            ex.printStackTrace();
            claim.getPanel().nextStep("Body not found!");
            continue;
        } catch (UnrecognizedCaptcha ex) {
            ex.printStackTrace();
            claim.getPanel().nextStep("Captcha not recognized.");
            continue;
        } catch (Exception ex) {
            continue;
        }

        claim.getPanel().nextStep("Trying auto resolving");
        // Intentamos buscar el hash en la DB 
        CaptchaHash ch = new CaptchaHash(captcha);
        String answer = CoinbotApplication.captchaDatabase.getAnswer(ch.getHash());

        // Si no enctramos la respuesta en la bd se la pedimos al usuario
        if (answer == null) {
            claim.getPanel().nextStep("Waiting for captcha answer ...");

            // Encolar captcha
            CoinbotApplication.bot.getCaptchaQueue().toQueue(captcha);

            // Esperar la resolucion del captcha
            CaptchaTimer timer = new CaptchaTimer(captcha, 35);
            timer.start();

            // Esperamos a la resolucion
            while (!timer.isExpired() && !captcha.resolved()) {
                CoinbotApplication.ui.captchaQueue.getCaptchaPanel(captcha).setTimer(timer.getSecondsLeft());
            }

            if (!captcha.resolved()) {
                CoinbotApplication.captchaDatabase.addCaptcha(ch);
                continue;
            }
        }

        // Guardamos el captcha en la DB
        CoinbotApplication.captchaDatabase.addCaptcha(new CaptchaHash(captcha));

        // Y la imagen en un archivo
        try {
            ImageIO.write(captcha.getImage(), "png", new File("coinbot/captchas/" + ch.getHash() + ".png"));
        } catch (IOException e) {
            e.printStackTrace();
        }

        // Envia la respuesta al input
        captcha.answerToInput(driver);

        // Desencolar captcha
        CoinbotApplication.bot.getCaptchaQueue().deQueue(captcha);

        // Escribir address
        claim.getPanel().nextStep("Detecting input address");
        InputAddressDetector iad = new InputAddressDetector(driver);
        iad.insertAddress(claim.getBtcAddress());

        //claim.getPanel().nextStep("Detecting Antibot");
        // Detectar antibot (puzzle no soportado)
        // Resolver antibot

        // submit
        claim.getPanel().nextStep("Submiting ...");
        WebElement submit = driver.findElement(By.id("address"));
        submit.submit();

        claim.getPanel().nextStep("Checking response");
        //claim.getPanel().nextStep("Successfull claim!");
        /*WebElement out = null;
                
        try {
           out = driver.findElement(By.className("alert-success"));
        } catch (NoSuchElementException e) {
                   
        }
                
        try {
           out = driver.findElement(By.className("alert-danger"));
        } catch (NoSuchElementException e) {
        }
        */
        //claim.getPanel().nextStep("Failed claim!");

        claim.getPanel().done();
        workerPanel.removeClaim(claim.getPanel());
        claim.getTimer().done(2000, 1);
        CoinbotApplication.bot.getClaimQueue().toQueue(claim);

        try {
            Thread.sleep(25000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        driver.close();
    } catch (Exception e) {

    }
    CoinbotApplication.ui.workerQueue.removeWorker(workerPanel);
    System.out.println("Worker " + workerId + " end work!");
}