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

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

Introduction

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

Prototype

public void setPreference(String key, Object value) 

Source Link

Usage

From source file:edu.umd.cs.guitar.ripper.WebDriverTest.java

License:Open Source License

@Test
public void testDriverBehaviors() {
    System.out.println("testDriverBehaviors");
    FirefoxProfile profile = new FirefoxProfile(new File("/home/baonn/.mozilla/firefox"));
    profile.setPreference("network.http.phishy-userpass-length", 255);
    FirefoxDriver driver = new FirefoxDriver(profile);
    driver.get("https://www.google.com/analytics/web/");

}

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 av  a 2  s .  c o  m*/
        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 {/*from ww  w .  j  a va  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   w w  w .ja va  2  s .c o 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());
}

From source file:evaluation.ExperimentRunner.java

License:Apache License

private void setup() throws Exception {
    System.out.println("xxx1");
    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    LoggingPreferences loggingPreferences = new LoggingPreferences();
    System.out.println("xxx2");
    loggingPreferences.enable(LogType.BROWSER, Level.ALL);
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
    FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinary));
    FirefoxProfile profile = new FirefoxProfile();
    System.out.println("xxx3");
    System.setProperty("webdriver.firefox.logfile", firefoxLogFile);
    profile.setPreference("webdriver.log.file", javascriptLogFile);
    profile.setPreference("dom.max_script_run_time", maxWaitTime);
    // Do not divert any links (browser.link.open_newwindow will have no
    // effect).// w  w  w. j  a va 2  s  .  c  o  m
    // http://kb.mozillazine.org/Browser.link.open_newwindow.restriction
    profile.setPreference("dom.popup_allowed_events", "");
    profile.setPreference("dom.popup_maximum", 0);
    profile.addExtension(new File(jalangiFFxpi));
    System.out.println("xxx4");
    driver = new FirefoxDriver(binary, profile, desiredCapabilities);
    System.out.println("xxx5");
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
    System.out.println("xxx6");
}

From source file:evaluation.JalangiFirefoxRunner.java

License:Apache License

private void setup() throws Exception {
    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    LoggingPreferences loggingPreferences = new LoggingPreferences();
    loggingPreferences.enable(LogType.BROWSER, Level.ALL);
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
    FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinary));
    FirefoxProfile profile = new FirefoxProfile();
    System.setProperty("webdriver.firefox.logfile", firefoxLogFile);
    profile.setPreference("webdriver.log.file", javascriptLogFile);
    profile.setPreference("dom.max_script_run_time", maxWaitTime);
    // Do not divert any links (browser.link.open_newwindow will have no effect). 
    // http://kb.mozillazine.org/Browser.link.open_newwindow.restriction
    profile.setPreference("dom.popup_allowed_events", "");
    profile.setPreference("dom.popup_maximum", 0);
    driver = new FirefoxDriver(binary, profile, desiredCapabilities);
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
}

From source file:evaluation.OctaneExperimentRunner.java

License:Apache License

private void run(String benchmark) throws Exception {
    DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
    LoggingPreferences loggingPreferences = new LoggingPreferences();
    loggingPreferences.enable(LogType.BROWSER, Level.ALL);
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
    FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinary));
    FirefoxProfile profile = new FirefoxProfile();
    System.setProperty("webdriver.firefox.logfile", firefoxLogFile);
    profile.setPreference("webdriver.log.file", javascriptLogFile);
    profile.setPreference("dom.max_script_run_time", maxWaitTime);
    profile.setPreference("extensions.sdk.console.logLevel", "info");
    profile.addExtension(new File(jalangiFFxpi));
    driver = new FirefoxDriver(binary, profile, desiredCapabilities);
    driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);

    testBenchmark(benchmark);/*from  w w w . j  a va2  s.c  o m*/

    driver.quit();
    System.out.println("Done :-)");
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.misc.MiscHandler1.java

License:Apache License

public void processDriver(WebDriver driver) {
    FirefoxProfile p = new FirefoxProfile();
    p.setPreference("webdriver_firefox_port", 8054);
    String URL = driver.getCurrentUrl();
    Site site = this.matches(URL);

    if (site == null)
        return;// w  ww .  j a va 2 s . co m

    System.out.println("Processing: " + URL);

    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    List<Action> actions = site.getActions();

    for (Action action : actions) {
        String actionType = action.getType();

        if (actionType.equals("input")) {
            WebElement element = findWebElement(action.getBy(), action.getValue(), driver);
            if (element == null)
                return;
            element.sendKeys(action.getKey());

        } else if (actionType.equals("click")) {
            WebElement element = findWebElement(action.getBy(), action.getValue(), driver);
            if (element == null)
                return;
            element.click();
            //Wait for a potential new page to load
            //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            //   driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        } else if (actionType.equals("redirect-append")) {
            //driver.navigate().to(action.getValue());
            //driver.get(action.getValue());//Exactly same as the above

            driver.get(URL + action.getValue());

            //Wait for a potential new page to load
            /* {
               Thread.sleep(10000);
            } catch(Exception e) {
               e.printStackTrace();
            }*/
        }
        driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    }
    driver.close();

}

From source file:integration.io.github.seleniumquery.browser.driver.builders.FirefoxDriverBuilderTest.java

License:Apache License

@Test
public void withProfile__should_set_the_given_profile() {
    // given/*  w  w w.j a  va2  s . co m*/
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("javascript.enabled", false);
    // when
    $.driver().useFirefox().withProfile(profile);
    // then
    assertJavaScriptIsOff($.driver().get());
}

From source file:io.github.bonigarcia.wdm.test.RemoteWebRtcFirefoxTest.java

License:Apache License

@Before
public void setupTest() throws MalformedURLException {
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    FirefoxProfile profile = new FirefoxProfile();
    profile.setPreference("media.navigator.permission.disabled", true);
    profile.setPreference("media.navigator.streams.fake", true);
    capability.setCapability(FirefoxDriver.PROFILE, profile);
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
}