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.zaizi.automation.alfresco.drivers.FirefoxDriverStore.java

License:Open Source License

/**
 * @return//from   www  . j  av  a  2s  .  co m
 */
public FirefoxDriver createWebDriver() {

    FirefoxProfile firefoxProfile = new FirefoxProfile();

    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    firefoxProfile.setPreference("browser.download.dir", TestCaseProperties.DEFAULT_DOWNLOAD_PATH);
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");
    firefoxProfile.setPreference("pdfjs.disabled", true);
    driver = new FirefoxDriver(firefoxProfile);
    return driver;
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

private static WebDriver createWebDriver() {
    if (SystemUtils.IS_WINDOWS) {
        return new InternetExplorerDriver();
    } else {/*  w  ww . ja v  a  2s .c o  m*/
        FirefoxProfile profile = new FirefoxProfile();
        String logFile = System.getProperty("selenium.firefox.log");
        if (logFile != null) {
            profile.setPreference("webdriver.log.file", logFile);
        }

        profile.setEnableNativeEvents(true);
        return new FirefoxDriver(profile);
    }
}

From source file:de.akquinet.devops.test.ui.generic.AbstractUITest.java

License:Apache License

/**
 * starts a gitblit server instance in a separate thread before test cases
 * of concrete, non-abstract child-classes are executed
 */// www .j  a  va  2 s .  co  m
@BeforeClass
public static void setUpClass() {
    Runnable gitblitRunnable = new GitblitRunnable(HTTP_PORT, HTTPS_PORT, SHUTDOWN_PORT,
            GITBLIT_PROPERTIES_PATH, USERS_PROPERTIES_PATH);

    serverThread = new Thread(gitblitRunnable);
    serverThread.start();
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("startup.homepage_welcome_url", "https://www.google.de");

    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    String downloadDir = System.getProperty("java.io.tmpdir");
    firefoxProfile.setPreference("browser.download.dir", downloadDir);
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
            "text/csv,text/plain,application/zip,application/pdf");
    firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
    System.out.println("Saving all attachments to: " + downloadDir);

    driver = new FirefoxDriver(firefoxProfile);
}

From source file:DerpSelenium.test.java

public static void loginMega(String username, String passwd) throws InterruptedException {
    FirefoxProfile profile = new FirefoxProfile();
    WebDriver driver = new FirefoxDriver(new FirefoxBinary(new File("/home/michael/bin/firefox")), profile);
    driver.get("http://www.mega.nz");
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override//from w w w.  jav  a 2  s.  c  o m
        public Boolean apply(WebDriver d) {
            try {
                WebElement loginButton = d.findElement(By.className("top-login-button"));
                System.out.println(loginButton.getText());
            } catch (NoSuchElementException e) {
                return false;
            }

            return true;
        }
    });

    WebElement loginButton = driver.findElement(By.xpath("//a[@class='top-login-button hidden']"));
    loginButton.click();
    WebElement nameElement = driver.findElement(By.name("login-name"));
    WebElement pwElement = driver.findElement(By.name("login-password"));
    nameElement.sendKeys(username);
    pwElement.sendKeys(passwd);
    WebElement submitButton = driver.findElement(By.className("top-dialog-login-button"));
    submitButton.click();

    Thread.sleep(15000);

    String url = driver.getCurrentUrl();
    List<WebElement> elements = driver.findElements(By.tagName("div"));
    Map<String, WebElement> elementMap = new HashMap<>();
    for (Iterator<WebElement> it = elements.iterator(); it.hasNext();) {
        WebElement e = it.next();
        try {
            if (!e.isDisplayed() || !e.isEnabled() || e.getAttribute("class").equals("")) {
                it.remove();
            } else {
                elementMap.put(e.getAttribute("class"), e);
            }
        } catch (StaleElementReferenceException ex) {
            it.remove();
        }

    }

    print("Number of added elements = " + elements.size());

    List<WebElement> contacts = driver
            .findElements(By.xpath("//div[@class='nw-fm-left-icon contacts ui-droppable']"));

    contacts.get(1).click();
    Thread.sleep(2000);
    //driver.navigate().back();
    //Thread.sleep(2000);
    WebElement el = elementMap.get("nw-fm-left-icon shared-with-me ui-droppable");
    if (el == null) {
        print("Element not found");
    } else {
        el.click();
    }

}

From source file:dk.netarkivet.systemtest.SeleniumTest.java

License:Open Source License

private void initialiseSelenium() {
    FirefoxProfile fxProfile = new FirefoxProfile();
    fxProfile.setPreference("browser.download.folderList", 2);
    fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    try {//from   ww w.ja v a 2s  .  c o m
        fxProfile.setPreference("browser.download.dir",
                (File.createTempFile("aaaa", "bbbb")).getParentFile().getAbsolutePath());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv");
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/xml");
    fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "binary/octet-stream");

    driver = new FirefoxDriver(fxProfile);
    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    baseUrl = testController.ENV.getGuiHost() + ":" + testController.ENV.getGuiPort();
    PageHelper.initialize(driver, baseUrl);
    TestGUIController.waitForGUIToStart(60);
    TestEventManager.getInstance().addFixture("Selecting English as language");
    driver.findElement(By.linkText("English")).click();
}

From source file:edu.samplu.common.WebDriverUtil.java

License:Educational Community License

/**
 * remote.public.driver set to chrome or firefox (null assumes firefox)
 * 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
 * @return WebDriver or null if unable to create
 *///w  ww  . ja v a2  s  .  c o  m
public static WebDriver getWebDriver() {
    String driverParam = System.getProperty(ITUtil.HUB_DRIVER_PROPERTY);
    String hubParam = System.getProperty(ITUtil.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(ITUtil.getHubUrlString()), DesiredCapabilities.firefox());
            } else if ("chrome".equalsIgnoreCase(driverParam)) {
                return new RemoteWebDriver(new URL(ITUtil.getHubUrlString()), DesiredCapabilities.chrome());
            }
        } catch (MalformedURLException mue) {
            System.out.println(ITUtil.getHubUrlString() + " " + mue.getMessage());
            mue.printStackTrace();
        }
    }
    return null;
}

From source file:edu.umd.cs.guitar.crawljax.browser.WebDriverBrowserWrapperBuilder.java

License:Open Source License

/**
 * Build a new WebDriver based EmbeddedBrowser.
 *
 * @see EmbeddedBrowserBuilder#buildEmbeddedBrowser(CrawljaxConfigurationReader)
 * @param configuration the configuration object to read the config values from
 * @return the new build WebDriver based embeddedBrowser
 *///from   ww  w .  ja va 2 s.  c o  m
@Override
public EmbeddedBrowser buildEmbeddedBrowser(CrawljaxConfigurationReader configuration) {
    // Retrieve the config values used
    List<String> filterAttributes = configuration.getFilterAttributeNames();
    int crawlWaitReload = configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl();
    int crawlWaitEvent = configuration.getCrawlSpecificationReader().getWaitAfterEvent();

    EmbeddedBrowser internalBrowser;
    // Determine the requested browser type
    switch (configuration.getBrowser()) {
    case firefox:
        if (configuration.getProxyConfiguration() != null) {
            FirefoxProfile profile = new FirefoxProfile();

            profile.setPreference("network.proxy.http", configuration.getProxyConfiguration().getHostname());
            profile.setPreference("network.proxy.http_port", configuration.getProxyConfiguration().getPort());
            profile.setPreference("network.proxy.type",
                    configuration.getProxyConfiguration().getType().toInt());
            profile.setPreference("network.proxy.no_proxies_on", "");
            internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(profile),
                    filterAttributes, crawlWaitReload, crawlWaitEvent);
            break;
        } else {
            internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(),
                    configuration.getFilterAttributeNames(),
                    configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                    configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
            break;
        }
    case ie:

        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new InternetExplorerDriver(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    case chrome:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new ChromeDriver(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    case remote:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withRemoteDriver(configuration.getRemoteHubUrl(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    case htmlunit:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new HtmlUnitDriver(true),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    default:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    }

    WebDriverBackedEmbeddedBrowserWraper browserWrapper = new WebDriverBackedEmbeddedBrowserWraper(
            internalBrowser);
    for (CJBrowserMonitor monitor : browserMonitorList) {
        browserWrapper.addMonitor(monitor);
    }
    return browserWrapper;
}

From source file:edu.usc.cs.ir.selenium.handler.Arguntrader.java

License:Apache License

public static void main(String[] args) {
    Arguntrader glocktalk = new Arguntrader();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
    profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
    profile.setPreference("permissions.default.stylesheet", 1);
    profile.setPreference("permissions.default.image", 1);

    FirefoxBinary binary = new FirefoxBinary();
    binary.setTimeout(TimeUnit.SECONDS.toMillis(180));

    WebDriver driver = new FirefoxDriver(binary, profile);
    driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS);

    try {/*from  w w w  .  j a  v  a2  s.  c  om*/
        driver.get("http://arguntrader.com/viewforum.php?f=8");
        System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            System.out.println("Timeout Exception");

            try {
                System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }
        e.printStackTrace();
    } finally {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }
}

From source file:edu.usc.cs.ir.selenium.handler.Glocktalk.java

License:Apache License

public static void main(String[] args) {
    Glocktalk glocktalk = new Glocktalk();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
    profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
    profile.setPreference("permissions.default.stylesheet", 1);
    profile.setPreference("permissions.default.image", 1);

    FirefoxBinary binary = new FirefoxBinary();
    binary.setTimeout(TimeUnit.SECONDS.toMillis(180));

    WebDriver driver = new FirefoxDriver(binary, profile);
    driver.manage().timeouts().pageLoadTimeout(10000, TimeUnit.MILLISECONDS);

    try {/*ww w  .  j a  v  a  2 s.c  o  m*/
        driver.get("http://www.glocktalk.com/media?page=6");
        System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
    } catch (Exception e) {
        if (e instanceof TimeoutException) {
            System.out.println("Timeout Exception");

            try {
                System.out.println(new String(glocktalk.processDriver(driver).getBytes("UTF-8")));
            } catch (UnsupportedEncodingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }
        //e.printStackTrace();
    } finally {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }
}

From source file:endtoend.browser.driver.builders.FirefoxDriverBuilderTest.java

License:Apache License

@Test
public void withProfile__should_set_the_given_profile() {
    // given/*from   ww  w  . j  av a  2 s. co m*/
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("browser.startup.homepage", "about:blank?setViaProfile");
    // when
    $.driver().useFirefox().autoDriverDownload().withProfile(profile).autoQuitDriver();
    // then
    $.driver().get();
    Assert.assertEquals("about:blank?setViaProfile", $.url());
}