Example usage for org.openqa.selenium.firefox FirefoxDriver PROFILE

List of usage examples for org.openqa.selenium.firefox FirefoxDriver PROFILE

Introduction

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

Prototype

String PROFILE

To view the source code for org.openqa.selenium.firefox FirefoxDriver PROFILE.

Click Source Link

Usage

From source file:org.cybercat.automation.browsers.RemoteServerProvider.java

License:Apache License

private DesiredCapabilities createDesiredCapabilities(Browsers browser) throws PageObjectException {
    try {//from w  w w  .j ava2s .c  o  m
        DesiredCapabilities capabilities = null;
        switch (browser) {
        case firefox:
            capabilities = DesiredCapabilities.firefox();
            String profileName = configProperties.getProperty("browser.profile.name", null);
            if (StringUtils.isNotBlank(profileName)) {
                ProfilesIni allProfiles = new ProfilesIni();
                FirefoxProfiler firefoxProfiler = new FirefoxProfiler();
                FirefoxProfile profile = firefoxProfiler
                        .addNetExportPreferences(allProfiles.getProfile(profileName));
                capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            }
            break;
        case chrome:
            capabilities = DesiredCapabilities.chrome();
            break;
        case internetExplorer:
            capabilities = DesiredCapabilities.internetExplorer();
            capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                    true);
            capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
            break;
        case safari:
            capabilities = DesiredCapabilities.safari();
            break;
        case android:
            capabilities = new DesiredCapabilities();
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("platformVersion", configProperties.getProperty("android.version"));
            capabilities.setCapability("deviceName", "Android Emulator");
            capabilities.setCapability("browserName", configProperties.getProperty("android.browser"));
            capabilities.setCapability("newCommandTimeout", "360");
            break;
        default:
            new PageObjectException("Browser type unsupported.");
            break;
        }
        return capabilities;
    } catch (Exception e) {
        throw new PageObjectException(
                "Remote browser initialization exception. Please check configuration parameters in property file.",
                e);
    }

}

From source file:org.jboss.arquillian.drone.webdriver.factory.FirefoxDriverFactory.java

License:Apache License

@Override
public FirefoxDriver createInstance(TypedWebDriverConfiguration<FirefoxDriverConfiguration> configuration) {

    String binary = configuration.getFirefoxBinary();
    String profile = configuration.getFirefoxProfile();

    DesiredCapabilities capabilities = new DesiredCapabilities(configuration.getCapabilities());

    // set binary and profile values
    if (Validate.nonEmpty(binary)) {
        Validate.isExecutable(binary, "Firefox binary does not point to a valid executable,  " + binary);
        log.log(Level.FINE, "Setting firefox binary to {0}", binary);
        capabilities.setCapability(FirefoxDriver.BINARY, binary);
    }//from  w  w  w  . ja  va 2 s.  c  o  m
    if (Validate.nonEmpty(profile)) {
        Validate.isValidPath(profile, "Firefox profile does not point to a valid path " + profile);
        log.log(Level.FINE, "Setting firefox profile to path {0}", profile);
        capabilities.setCapability(FirefoxDriver.PROFILE, new FirefoxProfile(new File(profile)));
    }

    return SecurityActions.newInstance(configuration.getImplementationClass(),
            new Class<?>[] { Capabilities.class }, new Object[] { capabilities }, FirefoxDriver.class);

}

From source file:org.kuali.rice.testtools.selenium.JenkinsJsonJobResultsBase.java

License:Educational Community License

public void setUp() throws MalformedURLException, InterruptedException {
    if (System.getProperty(JENKINS_JOBS) == null) {
        System.out.println("Don't know what jobs to retrieve.  -D" + JENKINS_JOBS + "= must be declared.");
        System.exit(1);/*ww  w.j a  v a  2s .c o  m*/
    }

    jenkinsBase = System.getProperty(JENKINS_BASE_URL, "http://ci.kuali.org");
    outputDirectory = System.getProperty(JSON_OUTPUT_DIR);

    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(false);

    downloadDir = System.getProperty(BROWSER_DOWNLOAD_DIR,
            System.getProperty("user.home") + File.separator + "Downloads");
    // download files automatically (don't prompt)
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.manager.showWhenStarting", false);
    profile.setPreference("browser.download.dir", downloadDir);
    profile.setPreference(BROWSER_HELPER_APPS_NEVER_ASK_SAVE_TO_DISK,
            System.getProperty(BROWSER_HELPER_APPS_NEVER_ASK_SAVE_TO_DISK, "application/zip"));

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
    driver.get(jenkinsBase + "/login?form");

    // CAS
    //        WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.id("username"),
    //                this.getClass().toString());
    //        driver.findElement(By.id("username")).sendKeys(System.getProperty(CAS_USERNAME));
    //        driver.findElement(By.id("password")).sendKeys(System.getProperty(CAS_PASSWORD));
    //        driver.findElement(By.name("submit")).click();
    //        Thread.sleep(1000);
    //
    //        exitOnLoginProblems();

    // Jenkins login page (don't login, we have authenticated through CAS already
    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(),
            By.xpath("//span[contains(text(), 'Page generated')]"), this.getClass().toString());

    // setup jobs builds
    jobsBuildsStrings = System.getProperty(JENKINS_JOBS).split("[,\\s]");
    String job;
    for (String jobsBuildsString : jobsBuildsStrings) {
        if (jobsBuildsString.contains(":")) {
            List<String> jobBuilds = Arrays.asList(jobsBuildsString.split(":"));
            job = jobBuilds.get(0); // first item is the job name
            jobs.add(job);
            if (jobBuilds.size() == 2 && "all".equals(jobBuilds.get(1))) { // job:all
                jobsBuildsMap.put(job, fetchAllJobNumbers(job));
            } else { // regular usage
                jobsBuildsMap.put(job, jobBuilds.subList(1, jobBuilds.size())); // first item is the job name
            }
        } else { // no jobNumbers specified, use last complete build number
            List<String> jobBuilds = new LinkedList<String>();
            jobBuilds.add(fetchLastCompletedBuildNumber(jobsBuildsString) + "");
            jobs.add(jobsBuildsString);
            jobsBuildsMap.put(jobsBuildsString, jobBuilds);
        }
    }

    passed = true;
}

From source file:org.kuali.rice.testtools.selenium.JenkinsJsonJobsResults.java

License:Educational Community License

@Before
public void setUp() throws MalformedURLException, InterruptedException {
    jenkinsBase = System.getProperty("jenkins.base.url", "http://ci.rice.kuali.org");
    outputDirectory = System.getProperty("json.output.dir");
    jobs = System.getProperty("jenkins.jobs", "rice-2.4-smoke-test").split("[,\\s]");

    DesiredCapabilities capabilities = new DesiredCapabilities();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(false);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
    driver.get(jenkinsBase + "/login?form");

    // CAS// www. j a va2s  .c  o  m
    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.id("username"),
            this.getClass().toString());
    driver.findElement(By.id("username")).sendKeys(System.getProperty("cas.username"));
    driver.findElement(By.id("password")).sendKeys(System.getProperty("cas.password"));
    driver.findElement(By.name("submit")).click();
    Thread.sleep(1000);
    if (driver.getPageSource().contains("The credentials you provided cannot be determined to be authentic.")) {
        System.out.println("CAS Login Error");
        System.exit(1);
    }

    // Jenkins login page (don't login, we have authenticated through CAS already
    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(),
            By.xpath("//span[contains(text(), 'Page generated')]"), this.getClass().toString());

    passed = true;
}

From source file:org.kuali.rice.testtools.selenium.JiraIssueCreation.java

License:Educational Community License

private void login() throws InterruptedException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(false);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    driver = new FirefoxDriver(capabilities);
    driver.manage().timeouts().implicitlyWait(WebDriverUtils.configuredImplicityWait(), TimeUnit.SECONDS);
    driver.get(jiraBase + "/secure/Dashboard.jspa");

    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.className("login-link"),
            this.getClass().toString()).click();

    // CAS//w ww .  j  a v a  2s  .  co m
    WebDriverUtils.waitFor(driver, WebDriverUtils.configuredImplicityWait(), By.id("username"),
            this.getClass().toString());
    driver.findElement(By.id("username")).sendKeys(System.getProperty("cas.username"));
    driver.findElement(By.id("password")).sendKeys(System.getProperty("cas.password"));
    driver.findElement(By.name("submit")).click();
}

From source file:org.kuali.rice.testtools.selenium.WebDriverUtils.java

License:Educational Community License

/**
 * <p>/*from w ww . j  a v  a  2 s  .co m*/
 * remote.public.driver set to chrome or firefox (null assumes firefox).
 * </p><p>
 * if remote.public.hub is set a RemoteWebDriver is created (Selenium Grid)
 * if proxy.host is set, the web driver is setup to use a proxy
 * </p>
 *
 * @return WebDriver or null if unable to create
 */
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(HUB_PROPERTY);
    String proxyParam = System.getProperty(PROXY_HOST_PROPERTY);

    // setup proxy if specified as VM Arg
    DesiredCapabilities capabilities = new DesiredCapabilities();
    WebDriver webDriver = null;
    if (StringUtils.isNotEmpty(proxyParam)) {
        capabilities.setCapability(CapabilityType.PROXY, new Proxy().setHttpProxy(proxyParam));
    }

    if (hubParam == null) {
        if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
            FirefoxProfile profile = new FirefoxProfile();
            profile.setEnableNativeEvents(false);
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            return new FirefoxDriver(capabilities);
        } else if ("chrome".equalsIgnoreCase(driverParam)) {
            return new ChromeDriver(capabilities);
        } else if ("safari".equals(driverParam)) {
            System.out.println("SafariDriver probably won't work, if it does please contact Erik M.");
            return new SafariDriver(capabilities);
        }
    } else {
        try {
            if (driverParam == null || "firefox".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}

From source file:org.kurento.test.browser.Browser.java

License:Apache License

private void createFirefoxBrowser(DesiredCapabilities capabilities) throws MalformedURLException {
    FirefoxProfile profile = new FirefoxProfile();
    // This flag avoids granting the access to the camera
    profile.setPreference("media.navigator.permission.disabled", true);

    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());

    // Firefox extensions
    if (extensions != null && !extensions.isEmpty()) {
        for (Map<String, String> extension : extensions) {
            InputStream is = getExtensionAsInputStream(extension.values().iterator().next());
            if (is != null) {
                try {
                    File xpi = File.createTempFile(extension.keySet().iterator().next(), ".xpi");
                    FileUtils.copyInputStreamToFile(is, xpi);
                    profile.addExtension(xpi);
                } catch (Throwable t) {
                    log.error("Error loading Firefox extension {} ({} : {})", extension, t.getClass(),
                            t.getMessage());
                }//from   w ww. j a v  a  2s.c o m
            }
        }
    }

    createDriver(capabilities, profile);
}

From source file:org.kurento.test.client.BrowserClient.java

License:Open Source License

public void init() {

    Class<? extends WebDriver> driverClass = browserType.getDriverClass();

    try {/*from   w  w  w.  j a v a2  s . co m*/
        DesiredCapabilities capabilities = new DesiredCapabilities();

        if (driverClass.equals(FirefoxDriver.class)) {
            FirefoxProfile profile = new FirefoxProfile();
            // This flag avoids granting the access to the camera
            profile.setPreference("media.navigator.permission.disabled", true);

            capabilities.setCapability(FirefoxDriver.PROFILE, profile);
            capabilities.setBrowserName(DesiredCapabilities.firefox().getBrowserName());

            // Firefox extensions
            if (extensions != null && !extensions.isEmpty()) {
                for (Map<String, String> extension : extensions) {
                    InputStream is = getExtensionAsInputStream(extension.values().iterator().next());
                    if (is != null) {
                        try {
                            File xpi = File.createTempFile(extension.keySet().iterator().next(), ".xpi");
                            FileUtils.copyInputStreamToFile(is, xpi);
                            profile.addExtension(xpi);
                        } catch (Throwable t) {
                            log.error("Error loading Firefox extension {} ({} : {})", extension, t.getClass(),
                                    t.getMessage());
                        }
                    }
                }
            }

            if (scope == BrowserScope.SAUCELABS) {
                createSaucelabsDriver(capabilities);
            } else if (scope == BrowserScope.REMOTE) {
                createRemoteDriver(capabilities);
            } else {
                driver = new FirefoxDriver(profile);
            }

        } else if (driverClass.equals(ChromeDriver.class)) {
            // Chrome driver
            ChromeDriverManager.getInstance().setup();

            // Chrome options
            ChromeOptions options = new ChromeOptions();

            // Chrome extensions
            if (extensions != null && !extensions.isEmpty()) {
                for (Map<String, String> extension : extensions) {
                    InputStream is = getExtensionAsInputStream(extension.values().iterator().next());
                    if (is != null) {
                        try {
                            File crx = File.createTempFile(extension.keySet().iterator().next(), ".crx");
                            FileUtils.copyInputStreamToFile(is, crx);
                            options.addExtensions(crx);
                        } catch (Throwable t) {
                            log.error("Error loading Chrome extension {} ({} : {})", extension, t.getClass(),
                                    t.getMessage());
                        }
                    }
                }
            }

            if (enableScreenCapture) {
                // This flag enables the screen sharing
                options.addArguments("--enable-usermedia-screen-capturing");

                String windowTitle = TEST_SCREEN_SHARE_TITLE_DEFAULT;
                if (platform != null && (platform == Platform.WINDOWS || platform == Platform.XP
                        || platform == Platform.VISTA || platform == Platform.WIN8
                        || platform == Platform.WIN8_1)) {

                    windowTitle = TEST_SCREEN_SHARE_TITLE_DEFAULT_WIN;
                }
                options.addArguments("--auto-select-desktop-capture-source="
                        + getProperty(TEST_SCREEN_SHARE_TITLE_PROPERTY, windowTitle));

            } else {
                // This flag avoids grant the camera
                options.addArguments("--use-fake-ui-for-media-stream");
            }

            // This flag avoids warning in Chrome. See:
            // https://code.google.com/p/chromedriver/issues/detail?id=799
            options.addArguments("--test-type");

            if (protocol == Protocol.FILE) {
                // This flag allows reading local files in video tags
                options.addArguments("--allow-file-access-from-files");
            }

            if (!usePhysicalCam) {
                // This flag makes using a synthetic video (green with
                // spinner) in WebRTC. Or it is needed to combine with
                // use-file-for-fake-video-capture to use a file faking the
                // cam
                options.addArguments("--use-fake-device-for-media-stream");

                if (video != null && isLocal()) {
                    options.addArguments("--use-file-for-fake-video-capture=" + video);
                }
            }

            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
            capabilities.setBrowserName(DesiredCapabilities.chrome().getBrowserName());

            if (scope == BrowserScope.SAUCELABS) {
                createSaucelabsDriver(capabilities);
            } else if (scope == BrowserScope.REMOTE) {
                createRemoteDriver(capabilities);
            } else {
                driver = new ChromeDriver(options);
            }
        } else if (driverClass.equals(InternetExplorerDriver.class)) {

            if (scope == BrowserScope.SAUCELABS) {
                capabilities.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());
                capabilities.setCapability("ignoreProtectedModeSettings", true);
                createSaucelabsDriver(capabilities);
            }

        } else if (driverClass.equals(SafariDriver.class)) {

            if (scope == BrowserScope.SAUCELABS) {
                capabilities.setBrowserName(DesiredCapabilities.safari().getBrowserName());
                createSaucelabsDriver(capabilities);
            }

        }

        // Timeouts
        changeTimeout(timeout);

        if (protocol == Protocol.FILE) {
            String clientPage = client.toString();
            File clientPageFile = new File(
                    this.getClass().getClassLoader().getResource("static" + clientPage).getFile());
            url = protocol.toString() + clientPageFile.getAbsolutePath();
        } else {
            String hostName = host != null ? host : node;
            url = protocol.toString() + hostName + ":" + serverPort + client.toString();
        }
        log.info("*** Browsing URL with WebDriver: {}", url);
        driver.get(url);

    } catch (MalformedURLException e) {
        log.error("MalformedURLException in BrowserClient.initDriver", e);
    }

    // startPing();
}

From source file:org.nuxeo.functionaltests.AbstractTest.java

License:Open Source License

protected static void initFirefoxDriver() throws Exception {
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    FirefoxProfile profile = new FirefoxProfile();
    // Disable native events (makes things break on Windows)
    profile.setEnableNativeEvents(false);
    // Set English as default language
    profile.setPreference("general.useragent.locale", "en");
    profile.setPreference("intl.accept_languages", "en");
    // Set other confs to speed up FF

    // Speed up firefox by pipelining requests on a single connection
    profile.setPreference("network.http.keep-alive", true);
    profile.setPreference("network.http.pipelining", true);
    profile.setPreference("network.http.proxy.pipelining", true);
    profile.setPreference("network.http.pipelining.maxrequests", 8);

    // Try to use less memory
    profile.setPreference("browser.sessionhistory.max_entries", 10);
    profile.setPreference("browser.sessionhistory.max_total_viewers", 4);
    profile.setPreference("browser.sessionstore.max_tabs_undo", 4);
    profile.setPreference("browser.sessionstore.interval", 1800000);

    // do not load images
    profile.setPreference("permissions.default.image", 2);

    // disable unresponsive script alerts
    profile.setPreference("dom.max_script_run_time", 0);
    profile.setPreference("dom.max_chrome_script_run_time", 0);

    // don't skip proxy for localhost
    profile.setPreference("network.proxy.no_proxies_on", "");

    // prevent different kinds of popups/alerts
    profile.setPreference("browser.tabs.warnOnClose", false);
    profile.setPreference("browser.tabs.warnOnOpen", false);
    profile.setPreference("extensions.newAddons", false);
    profile.setPreference("extensions.update.notifyUser", false);

    // disable autoscrolling
    profile.setPreference("browser.urlbar.autocomplete.enabled", false);

    // downloads conf
    profile.setPreference("browser.download.useDownloadDir", false);

    // prevent FF from running in offline mode when there's no network
    // connection
    profile.setPreference("toolkit.networkmanager.disable", true);

    // prevent FF from giving health reports
    profile.setPreference("datareporting.policy.dataSubmissionEnabled", false);
    profile.setPreference("datareporting.healthreport.uploadEnabled", false);
    profile.setPreference("datareporting.healthreport.service.firstRun", false);
    profile.setPreference("datareporting.healthreport.service.enabled", false);
    profile.setPreference("datareporting.healthreport.logging.consoleEnabled", false);

    // start page conf to speed up FF
    profile.setPreference("browser.startup.homepage", "about:blank");
    profile.setPreference("pref.browser.homepage.disable_button.bookmark_page", false);
    profile.setPreference("pref.browser.homepage.disable_button.restore_default", false);

    // misc confs to avoid useless updates
    profile.setPreference("browser.search.update", false);
    profile.setPreference("browser.bookmarks.restore_default_bookmarks", false);

    // misc confs to speed up FF
    profile.setPreference("extensions.ui.dictionary.hidden", true);
    profile.setPreference("layout.spellcheckDefault", 0);

    addFireBug(profile);/*from   ww  w.jav a2s.  c  o  m*/
    Proxy proxy = startProxy();
    if (proxy != null) {
        // Does not work, but leave code for when it does
        // Workaround: use 127.0.0.2
        proxy.setNoProxy("");
        profile.setProxyPreferences(proxy);
    }
    dc.setCapability(FirefoxDriver.PROFILE, profile);
    driver = new FirefoxDriver(dc);
}

From source file:org.nuxeo.functionaltests.drivers.FirefoxDriverProvider.java

License:Open Source License

@Override
public RemoteWebDriver init(DesiredCapabilities dc) throws Exception {

    FirefoxProfile profile = getProfile();

    JavaScriptError.addExtension(profile);

    dc.setCapability(FirefoxDriver.PROFILE, profile);
    driver = new FirefoxDriver(dc);
    return driver;
}