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:wsattacker.sso.openid.attacker.evaluation.SeleniumBrowser.java

License:Open Source License

public static WebDriver getWebDriver() {

    if (INSTANCE == null || hasQuit(INSTANCE) || INSTANCE.getWindowHandles().isEmpty()) {
        // create chrome profile
        //ChromeOptions options = new ChromeOptions();
        //options.addExtensions(new File("adblock.crx"));

        FirefoxProfile profile = new FirefoxProfile();

        // install adblock plus
        File tmpFile = new File("adblock.xpi");
        try {/* ww w . j  a va2s. c om*/
            InputStream inputStream = SeleniumBrowser.class.getResourceAsStream("/adblock_firefox.xpi");
            FileUtils.copyInputStreamToFile(inputStream, tmpFile);
            profile.addExtension(tmpFile);
        } catch (IOException ex) {
            Logger.getLogger(EvaluationGui.class.getName()).log(Level.SEVERE, null, ex);
        }

        // disable local and session storage
        // some websites (e.g. stackoverflow) use those storages in addition
        // to session cookies
        profile.setPreference("dom.storage.enabled", false);

        // start new Firefox instance
        INSTANCE = new FirefoxDriver(profile);

        // screen size
        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int width = gd.getDisplayMode().getWidth();
        int height = gd.getDisplayMode().getHeight();

        width = width > 1440 ? 1440 : width;
        height = height > 900 ? 900 : height;

        INSTANCE.manage().window().setPosition(new Point(0, 0));
        INSTANCE.manage().window().setSize(new Dimension(width, height));

        tmpFile.delete();
    }

    return INSTANCE;
}