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

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

Introduction

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

Prototype

public FirefoxBinary() 

Source Link

Usage

From source file:org.apache.zeppelin.WebDriverManager.java

License:Apache License

public static WebDriver getWebDriver() {
    WebDriver driver = null;//from   w w w. ja v a2s .  c  o m

    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                // run with DISPLAY 99
            }
            int firefoxVersion = WebDriverManager.getFirefoxVersion();
            LOG.info("Firefox version " + firefoxVersion + " detected");

            downLoadsDir = FileUtils.getTempDirectory().toString();

            String tempPath = downLoadsDir + "/firefox/";

            downloadGeekoDriver(firefoxVersion, tempPath);

            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.dir", downLoadsDir);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", true);
            profile.setPreference("app.update.auto", false);
            profile.setPreference("app.update.enabled", false);
            profile.setPreference("dom.max_script_run_time", 0);
            profile.setPreference("dom.max_chrome_script_run_time", 0);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
            profile.setPreference("network.proxy.type", 0);

            System.setProperty(GeckoDriverService.GECKO_DRIVER_EXE_PROPERTY, tempPath + "geckodriver");
            System.setProperty(SystemProperty.DRIVER_USE_MARIONETTE, "false");

            FirefoxOptions firefoxOptions = new FirefoxOptions();
            firefoxOptions.setBinary(ffox);
            firefoxOptions.setProfile(profile);
            driver = new FirefoxDriver(firefoxOptions);
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }

    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@uib-tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    driver.manage().window().maximize();
    return driver;
}

From source file:org.apache.zeppelin.ZeppelinIT.java

License:Apache License

private WebDriver getWebDriver() {
    WebDriver driver = null;/*  w ww .  jav  a  2s . c o m*/

    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                ffox.setEnvironmentProperty("DISPLAY", ":99"); // xvfb is supposed to
                                                               // run with DISPLAY 99
            }
            FirefoxProfile profile = new FirefoxProfile();
            driver = new FirefoxDriver(ffox, profile);
        } catch (Exception e) {
        }
    }

    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
        }
    }

    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
        }
    }

    String url;
    if (System.getProperty("url") != null) {
        url = System.getProperty("url");
    } else {
        url = "http://localhost:8080";
    }

    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.get(url);

    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() {
                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.partialLinkText("Create new note")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            driver.navigate().to(url);
        }
    }

    if (loaded == false) {
        fail();
    }

    return driver;
}

From source file:org.asqatasun.sebuilder.interpreter.webdriverfactory.FirefoxDriverFactory.java

License:Open Source License

/**
 * //  w  w  w. j  av  a 2 s  .  c om
 * @param config
 * @return A FirefoxDriver.
 */
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY) != null) {
        ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getProperty(DISPLAY_PROPERTY));
    } else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) {
        ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(),
                System.getenv(DISPLAY_PROPERTY.toUpperCase()));
    }
    RemoteWebDriver remoteWebDriver = new FirefoxDriver(ffBinary, firefoxProfile);

    if (screenHeight != -1 && screenWidth != -1) {
        remoteWebDriver.manage().window().setSize(new Dimension(screenWidth, screenHeight));
    }
    return remoteWebDriver;
}

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

License:Open Source License

@Override
public FirefoxDriver makeObject() throws Exception {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY_KEY) != null) {
        Logger.getLogger(this.getClass())
                .info("Setting Xvfb display with value " + System.getProperty(DISPLAY_PROPERTY_KEY));
        ffBinary.setEnvironmentProperty("DISPLAY", System.getProperty(DISPLAY_PROPERTY_KEY));
    }/*  w ww .  j  av a2  s. c o m*/
    FirefoxDriver fd = new FirefoxDriver(ffBinary, ProfileFactory.getInstance().getScenarioProfile());
    if (this.implicitelyWaitDriverTimeout != null) {
        fd.manage().timeouts().implicitlyWait(this.implicitelyWaitDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    if (this.pageLoadDriverTimeout != null) {
        fd.manage().timeouts().pageLoadTimeout(this.pageLoadDriverTimeout.longValue(), TimeUnit.SECONDS);
    }
    return fd;
}

From source file:org.asqatasun.tgol.test.scenario.AbstractWebDriverTestClass.java

License:Open Source License

/**
 *
 *//* w  w w .j  a va2s.c  om*/
private void initialize() {

    // Mysql access parameters are passed as JVM argument
    //        dbUrl = System.getProperty(DB_URL_KEY);
    //        dbName = System.getProperty(DB_NAME_KEY);
    //        dbUser = System.getProperty(DB_USER_KEY);
    //        dbPassword = System.getProperty(DB_PASSWORD_KEY);
    //        initDb();

    // These parameters has to passed as JVM argument
    user = System.getProperty(USER_KEY);
    password = System.getProperty(PASSWORD_KEY);
    hostLocation = System.getProperty(HOST_LOCATION_KEY);
    xvfbDisplay = System.getProperty(XVFB_DISPLAY_KEY);

    //        createRootUserInDb();

    ResourceBundle parametersBundle = ResourceBundle.getBundle(BUNDLE_NAME);
    userFieldName = parametersBundle.getString(USER_FIELD_NAME_KEY);
    passwordFieldName = parametersBundle.getString(PASSWORD_FIELD_NAME_KEY);
    loginUrl = hostLocation + parametersBundle.getString(LOGIN_URL_KEY);
    logoutUrl = hostLocation + parametersBundle.getString(LOGOUT_URL_KEY);
    adminUrl = hostLocation + parametersBundle.getString(ADMIN_URL_KEY);
    addUserUrl = hostLocation + parametersBundle.getString(ADD_USER_URL_KEY);
    editUserUrl = hostLocation + parametersBundle.getString(EDIT_USER_URL_KEY);
    deleteUserUrl = hostLocation + parametersBundle.getString(DELETE_USER_URL_KEY);
    addContractUrl = hostLocation + parametersBundle.getString(ADD_CONTRACT_URL_KEY);
    contractUrl = hostLocation + parametersBundle.getString(CONTRACT_URL_KEY);
    auditPagesSetupUrl = hostLocation + parametersBundle.getString(AUDIT_PAGES_URL_KEY);
    auditSiteSetupUrl = hostLocation + parametersBundle.getString(AUDIT_SITE_URL_KEY);
    auditUploadSetupUrl = hostLocation + parametersBundle.getString(AUDIT_UPLOAD_URL_KEY);
    auditScenarioSetupUrl = hostLocation + parametersBundle.getString(AUDIT_SCENARIO_URL_KEY);
    addUserContractUrl = hostLocation + parametersBundle.getString(ADD_USER_CONTRACT_URL_KEY);
    editUserContractUrl = hostLocation + parametersBundle.getString(EDIT_USER_CONTRACT_URL_KEY);

    if (driver == null) {
        FirefoxBinary ffBinary = new FirefoxBinary();
        if (xvfbDisplay != null) {
            Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + xvfbDisplay);
            ffBinary.setEnvironmentProperty("DISPLAY", xvfbDisplay);
        }
        driver = new FirefoxDriver(ffBinary, new FirefoxProfile());
    }
}

From source file:org.asqatasun.webapp.test.WebDriverFactory.java

License:Open Source License

/**
 * This methods creates a firefoxDriver instance and set a DISPLAY 
 * environment variable/*from  w w  w . j  av a 2s  .c  om*/
 * @param display
 * @return an instance of firefoxDriver 
 */
public FirefoxDriver getFirefoxDriver(String display) {
    if (webDriver == null) {
        FirefoxBinary ffBinary = new FirefoxBinary();
        if (StringUtils.isNotBlank(display)) {
            Logger.getLogger(this.getClass()).info("Setting Xvfb display with value " + display);
            ffBinary.setEnvironmentProperty("DISPLAY", display);
        }
        ProfileFactory pf = ProfileFactory.getInstance();
        webDriver = new FirefoxDriver(ffBinary, pf.getOnlineProfile());
        webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        webDriver.manage().timeouts().pageLoadTimeout(310, TimeUnit.SECONDS);
    }
    return webDriver;
}

From source file:org.bigtester.ate.model.page.atewebdriver.MyFirefoxDriver.java

License:Apache License

/**
 * {@inheritDoc}//from  w  ww. j  a v a2  s.co  m
 */
@Override
public WebDriver getWebDriverInstance() {
    WebDriver retVal = super.getWebDriver();
    if (null == retVal) {
        BrowserProfile<FirefoxProfile> bPro = getBrowserProfile();
        if (null == bPro) {
            retVal = new FirefoxDriver();
        } else {
            FirefoxBinary binary = new FirefoxBinary();
            binary.addCommandLineOptions("-no-remote");
            retVal = new FirefoxDriver(binary, bPro.getProfile());
        }
        setWebDriver(retVal);

    }
    return retVal;
}

From source file:org.emonocot.portal.driver.WebDriverFacade.java

License:Open Source License

/**
 *
 * @return the webdriver/*from   w  w  w  .  jav a 2s . c  om*/
 * @throws IOException if there is a problem loading the
 *                     properties file
 */
private WebDriver createWebDriver() throws IOException {
    Resource propertiesFile = new ClassPathResource("META-INF/spring/application.properties");
    Properties properties = new Properties();
    properties.load(propertiesFile.getInputStream());
    String webdriverMode = properties.getProperty("selenium.webdriver.mode", "local");
    String driverName = properties.getProperty("selenium.webdriver.impl",
            "org.openqa.selenium.firefox.FirefoxDriver");
    WebDriverBrowserType browser = WebDriverBrowserType.fromString(driverName);
    String display = properties.getProperty("selenium.display.port", ":0");
    if (webdriverMode.equals("local")) {
        switch (browser) {
        case CHROME:
            String chromeLocation = properties.getProperty("selenium.webdriver.chromedriver.location");
            Map<String, String> environment = new HashMap<String, String>();
            environment.put("DISPLAY", display);
            ChromeDriverService chromeService = new ChromeDriverService.Builder()
                    .usingDriverExecutable(new File(chromeLocation)).usingAnyFreePort()
                    .withEnvironment(environment).build();
            chromeService.start();
            return new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome());
        case SAFARI:
            return new SafariDriver();
        case INTERNET_EXPLORER:
            String internetExplorerLocation = properties.getProperty("selenium.webdriver.ie.location");
            InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService();
            ieService.start();
            return new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer());
        case FIREFOX:
        default:
            FirefoxBinary firefoxBinary = new FirefoxBinary();
            firefoxBinary.setEnvironmentProperty("DISPLAY", display);
            ProfilesIni allProfiles = new ProfilesIni();
            FirefoxProfile profile = allProfiles.getProfile("default");
            return new FirefoxDriver(firefoxBinary, profile);
        }
    } else {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        switch (browser) {
        case CHROME:
            capabilities = DesiredCapabilities.chrome();
            break;
        case INTERNET_EXPLORER:
            capabilities = DesiredCapabilities.internetExplorer();
            break;
        case SAFARI:
            capabilities = DesiredCapabilities.safari();
            break;
        case FIREFOX:
        default:
            capabilities = DesiredCapabilities.firefox();
        }
        String platformName = properties.getProperty("selenium.webdriver.platformName", "LINUX");
        WebDriverPlatformType platform = WebDriverPlatformType.valueOf(platformName);
        switch (platform) {
        case MAC:
            capabilities.setPlatform(Platform.MAC);
            break;
        case WINDOWS:
            capabilities.setPlatform(Platform.WINDOWS);
            break;
        case LINUX:
        default:
            capabilities.setPlatform(Platform.LINUX);
        }
        return new RemoteWebDriver(new URL("http://build.e-monocot.org:4444/wd/hub"), capabilities);
    }
}

From source file:org.opens.tanaguru.sebuilder.interpreter.webdriverfactory.FirefoxDriverFactory.java

License:Apache License

/**
 * /*w  ww  . jav  a 2 s.  c  o m*/
 * @param config
 * @return A FirefoxDriver.
 */
@Override
public RemoteWebDriver make(HashMap<String, String> config) {
    FirefoxBinary ffBinary = new FirefoxBinary();
    if (System.getProperty(DISPLAY_PROPERTY) != null) {
        ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(), System.getProperty(DISPLAY_PROPERTY));
    } else if (System.getenv(DISPLAY_PROPERTY.toUpperCase()) != null) {
        ffBinary.setEnvironmentProperty(DISPLAY_PROPERTY.toUpperCase(),
                System.getenv(DISPLAY_PROPERTY.toUpperCase()));
    }
    return new FirefoxDriver(ffBinary, firefoxProfile);
}

From source file:org.sugarcrm.voodoodriver.Firefox.java

License:Apache License

/**
 * Create a new firefox browser instance.
 */// ww  w .java  2  s.com

public void newBrowser() {
    FirefoxBinary b = new FirefoxBinary();
    FirefoxProfile p = null;
    if (this.profile == null) {
        p = new FirefoxProfile();
    } else {
        p = new FirefoxProfile(new java.io.File(this.profile));
    }

    if (this.downloadDirectory != null) {
        try {
            p.setPreference("browser.download.dir", this.downloadDirectory);
        } catch (java.lang.IllegalArgumentException e) {
            System.err.println("Ill-formed downloaddir '" + this.downloadDirectory + "'");
            System.exit(1);
        }
        p.setPreference("browser.download.manager.closeWhenDone", true);
        p.setPreference("browser.download.manager.retention", 0);
        p.setPreference("browser.download.manager.showAlertOnComplete", false);
        p.setPreference("browser.download.manager.scanWhenDone", false);
        p.setPreference("browser.download.manager.skipWinSecurityPolicyChecks", true);
        p.setPreference("browser.startup.page", 0);
        p.setPreference("browser.download.manager.alertOnEXEOpen", false);
        p.setPreference("browser.download.manager.focusWhenStarting", false);
        p.setPreference("browser.download.useDownloadDir", true);
    }

    if (this.webDriverLogDirectory != null) {
        File wdl = makeLogfileName(this.webDriverLogDirectory, "webdriver");
        File fl = makeLogfileName(this.webDriverLogDirectory, "firefox");

        System.out.println("(*) Creating WebDriver log " + wdl);
        p.setPreference("webdriver.log.file", wdl.toString());

        System.out.println("(*) Creating Firefox log " + fl);
        p.setPreference("webdriver.firefox.logfile", fl.toString());
    }

    DesiredCapabilities c = new DesiredCapabilities();
    c.setCapability("unexpectedAlertBehaviour", "ignore");

    FirefoxDriver ff = new FirefoxDriver(b, p, c);
    this.setDriver(ff);
    this.setBrowserOpened();
}