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:org.usapi.SeleniumFactory.java

License:Apache License

/**
 * Returns an instance of WebDriver.//ww  w  . j  ava  2  s.co m
 *
 * This is a singleton that is instantiated with parameters 
 * from system properties with overrides
 */
public static WebDriver getWebDriverInstance() {
    if (webDriver == null) {
        String browser = PropertyHelper.getSeleniumBrowserCommand();

        String seleniumServerHost = PropertyHelper.getSeleniumServerHost();
        String seleniumServerPort = PropertyHelper.getSeleniumServerPort();
        // if selenium server host/port properties are set, they were passed in via 
        // .properties or -D.  Either way, this tells us that we are running on the
        // grid and need to instantiate our web driver such that it knows to use
        // selenium server
        if (seleniumServerHost.length() > 0 && seleniumServerPort.length() > 0) {
            URL seleniumServerUrl = null;
            try {
                seleniumServerUrl = new URL(
                        "http://" + seleniumServerHost + ":" + seleniumServerPort + "/wd/hub");
            } catch (MalformedURLException e) {
                // this should never happen, as the default values for serverHost and port are localhost and 4444.  Only if
                // overrides (from .properties or cmd line) result in an invalid URL this exception handler would get invoked.
                log.error("Invalid value for Selenium Server Host or Selenium Server Port.  Provided values: <"
                        + seleniumServerHost + "> <" + seleniumServerPort + ">");

            }
            DesiredCapabilities capability = getDesiredCapabilities(browser);
            if (browser.toLowerCase().contains(BROWSER_TYPE_FIREFOX)) {
                capability.setCapability("nativeEvents", PropertyHelper.getEnableNativeEvents());
                capability.setCapability("name", "Remote File Upload using Selenium 2's FileDetectors");
            }
            RemoteWebDriver rwd = new RemoteWebDriver(seleniumServerUrl, capability);
            rwd.setFileDetector(new LocalFileDetector());
            webDriver = new Augmenter().augment((WebDriver) rwd);
        }
        // no, we are not running on the grid.  Just instantiate the driver for the desired
        // browser directly.
        else {
            if (browser.toLowerCase().contains(BROWSER_TYPE_FIREFOX)) {
                FirefoxProfile p = new FirefoxProfile();
                p.setEnableNativeEvents(PropertyHelper.getEnableNativeEvents());
                webDriver = new FirefoxDriver(p);
            } else if (browser.toLowerCase().contains(BROWSER_TYPE_IEXPLORE)) {
                webDriver = new InternetExplorerDriver();
            } else if (browser.toLowerCase().contains(BROWSER_TYPE_CHROME)) {
                webDriver = new RemoteWebDriver(getChromeDriverURL(), DesiredCapabilities.chrome());
                webDriver = new Augmenter().augment((WebDriver) webDriver);
            } else if (browser.toLowerCase().contains(BROWSER_TYPE_SAFARI)) {
                webDriver = new SafariDriver();
            } else if (browser.toLowerCase().contains(BROWSER_TYPE_HTMLUNIT)) {
                DesiredCapabilities capabilities = getDesiredCapabilities(browser);
                capabilities.setJavascriptEnabled(PropertyHelper.getHtmlUnitEnableJavascript());

                webDriver = new HtmlUnitDriver(capabilities);
            }
        }

        // default in PropertyHelper is 0.  Set this options only if they were explicitly specified (.properties or 
        // in the environment
        long scriptTimeout = PropertyHelper.getScriptTimeout();
        long implicitlyWait = PropertyHelper.getImplicitlyWait();
        long pageLoadTimeout = PropertyHelper.getPageLoadTimeout();
        if (scriptTimeout > 0)
            webDriver.manage().timeouts().setScriptTimeout(scriptTimeout, TimeUnit.MILLISECONDS);
        if (implicitlyWait > 0)
            webDriver.manage().timeouts().implicitlyWait(implicitlyWait, TimeUnit.MILLISECONDS);
        if (pageLoadTimeout > 0)
            webDriver.manage().timeouts().pageLoadTimeout(pageLoadTimeout, TimeUnit.MILLISECONDS);
    }
    return webDriver;
}

From source file:org.wso2.am.integration.ui.tests.APIMANAGER4006SampleApiDeploymentTestCase.java

License:Open Source License

@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    firefoxProfile.setPreference("browser.download.dir", System.getProperty("download.location"));
    firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
    //Set browser settings to automatically download wsdl files
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/force-download");
    driver = new FirefoxDriver(firefoxProfile);
    wait = new WebDriverWait(driver, 60);
}

From source file:org.xwiki.test.ui.WebDriverFactory.java

License:Open Source License

public WebDriver createWebDriver(String browserName) {
    WebDriver driver;/*from  w  w  w. j a va  2s  .c om*/
    if (browserName.startsWith("*firefox")) {
        // Native events are disabled by default for Firefox on Linux as it may cause tests which open many windows
        // in parallel to be unreliable. However, native events work quite well otherwise and are essential for some
        // of the new actions of the Advanced User Interaction. We need native events to be enable especially for
        // testing the WYSIWYG editor. See http://code.google.com/p/selenium/issues/detail?id=2331 .
        FirefoxProfile profile = new FirefoxProfile();
        profile.setEnableNativeEvents(true);
        // Make sure Firefox doesn't upgrade automatically on CI agents.
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("app.update.silent", false);
        driver = new FirefoxDriver(profile);

        // Hide the Add-on bar (from the bottom of the window, with "WebDriver" written on the right) because it can
        // prevent buttons or links from being clicked when they are beneath it and native events are used.
        // See https://groups.google.com/forum/#!msg/selenium-users/gBozOynEjs8/XDxxQNmUSCsJ
        // We need to load a page before sending the keys otherwise WebDriver throws ElementNotVisible exception.
        driver.get("data:text/plain;charset=utf-8,XWiki");
        driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.CONTROL, "/"));
    } else if (browserName.startsWith("*iexplore")) {
        driver = new InternetExplorerDriver();
    } else if (browserName.startsWith("*chrome")) {
        driver = new ChromeDriver();
    } else if (browserName.startsWith("*phantomjs")) {
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setCapability("handlesAlerts", true);
        try {
            driver = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("Unsupported browser name [" + browserName + "]");
    }

    // Maximize the browser window by default so that the page has a standard layout. Individual tests can resize
    // the browser window if they want to test how the page layout adapts to limited space. This reduces the
    // probability of a test failure caused by an unexpected layout (nested scroll bars, floating menu over links
    // and buttons and so on).
    driver.manage().window().maximize();

    return driver;
}

From source file:org.zanata.page.WebDriverFactory.java

License:Open Source License

private FirefoxProfile makeFirefoxProfile() {
    if (!Strings.isNullOrEmpty(System.getProperty("webdriver.firefox.profile"))) {
        throw new RuntimeException("webdriver.firefox.profile is ignored");
        // TODO - look at FirefoxDriver.getProfile().
    }/*from   ww  w  . j  av  a2  s.  c o m*/
    final FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setAlwaysLoadNoFocusLib(true);
    firefoxProfile.setEnableNativeEvents(true);
    firefoxProfile.setAcceptUntrustedCertificates(true);
    // TODO port zanata-testing-extension to firefox
    //        File file = new File("extension.xpi");
    //        firefoxProfile.addExtension(file);
    return firefoxProfile;
}

From source file:pagelyzer.BrowserRep.java

License:Open Source License

/**
 * Set the selenium driver as local (webdriver instance)
 *//*from   w  w  w .j a  va  2 s .c o  m*/
public void setLocalDriver() {
    switch (this.desc) {
    case "firefox":
        FirefoxProfile profile = new FirefoxProfile();
        profile.setPreference("browser.download.lastDir", "/home/sanojaa/src/migration425/sources/inbox/pages");
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.dir", "/home/sanojaa/src/migration425/sources/inbox/pages");
        profile.setEnableNativeEvents(true);
        this.driver = new FirefoxDriver(profile);
        break;
    case "iexplorer":
        this.driver = new InternetExplorerDriver();
        break;
    case "chrome":
        this.driver = new ChromeDriver();
        break;
    case "opera":
        this.driver = new OperaDriver();
        break;
    case "htmlunit":
        this.driver = new HtmlUnitDriver();
        break;
    }
    setJSDriver();
    this.driver.manage().timeouts().pageLoadTimeout(MAX_WAIT_S, TimeUnit.SECONDS);
    this.driver.manage().timeouts().implicitlyWait(MAX_WAIT_S, TimeUnit.SECONDS);
}

From source file:pawl.webdriver.LocalizedWebDriverProvider.java

License:Apache License

/**
 * Provide new Firefox driver with setup of user language.
 *
 * @return firefox driver/*from   w w w  .  ja  v  a2 s .  c  om*/
 */
protected FirefoxDriver createFirefoxDriver() {
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("intl.accept_languages", getSystemLanguage());
    FirefoxDriver firefoxDriver = new FirefoxDriver(firefoxProfile);
    firefoxDriver.manage().window().maximize();
    return firefoxDriver;
}

From source file:plugins.KerberosSsoTest.java

License:Open Source License

private FirefoxDriver getNegotiatingFirefox(KerberosContainer kdc, String tokenCache) {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAlwaysLoadNoFocusLib(true);
    // Allow auth negotiation for jenkins under test
    profile.setPreference("network.negotiate-auth.trusted-uris", jenkins.url.toExternalForm());
    profile.setPreference("network.negotiate-auth.delegation-uris", jenkins.url.toExternalForm());
    FirefoxBinary binary = new FirefoxBinary();
    // Inject config and TGT
    binary.setEnvironmentProperty("KRB5CCNAME", tokenCache);
    binary.setEnvironmentProperty("KRB5_CONFIG", kdc.getKrb5ConfPath());
    // Turn debug on
    binary.setEnvironmentProperty("KRB5_TRACE", diag.touch("tracelog").getAbsolutePath());
    binary.setEnvironmentProperty("NSPR_LOG_MODULES", "negotiateauth:5");
    binary.setEnvironmentProperty("NSPR_LOG_FILE", diag.touch("firefox.nego.log").getAbsolutePath());

    String display = FallbackConfig.getBrowserDisplay();
    if (display != null) {
        binary.setEnvironmentProperty("DISPLAY", display);
    }/*from w ww.j a  v  a 2  s  . c  o  m*/
    final FirefoxDriver driver = new FirefoxDriver(binary, profile);
    cleaner.addTask(new Statement() {
        @Override
        public void evaluate() throws Throwable {
            try {
                driver.quit();
            } catch (UnreachableBrowserException ex) {
                System.err.println("Browser died already");
                ex.printStackTrace();
            }
        }

        @Override
        public String toString() {
            return "Close Kerberos WebDriver after test";
        }
    });
    return driver;
}

From source file:renascere.Renascere.java

License:Open Source License

/**
 * @Description Method that opens a specified browser
 *//*from  w  ww. j a  va 2 s .c  o  m*/
static WebDriver openABrowser(browser bBrowserName) {
    WebDriver driver = null;
    String sDriverName = null;
    DesiredCapabilities DesireCaps = new DesiredCapabilities();

    try {
        //Creating browser instance
        switch (bBrowserName) {
        case FIREFOX:
            //Initializing Driver
            FirefoxProfile browserProfile = new FirefoxProfile();

            //Adding following preferences to download files
            browserProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");
            browserProfile.setPreference("browser.download.folderList", 2);
            browserProfile.setPreference("browser.download.dir", Vars.os_PathOut);
            browserProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            browserProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",
                    "application/msword, application/csv, "
                            + "application/ris, text/csv, image/png, application/pdf, text/html, "
                            + "text/plain, application/zip, application/x-zip, application/x-zip-compressed, "
                            + "application/download, application/octet-stream");
            browserProfile.setPreference("browser.download.manager.showWhenStarting", false);
            browserProfile.setPreference("browser.download.manager.focusWhenStarting", false);
            browserProfile.setPreference("browser.download.useDownloadDir", true);
            browserProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
            browserProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            browserProfile.setPreference("browser.download.manager.closeWhenDone", true);
            browserProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
            browserProfile.setPreference("browser.download.manager.useWindow", false);
            browserProfile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting",
                    false);
            browserProfile.setPreference("pdfjs.disabled", true);
            browserProfile.setPreference("browser.download.manager.openDelay", 100000);
            browserProfile.setPreference("browser.download.animateNotifications", false);
            driver = new FirefoxDriver(browserProfile);
            break;
        case CHROME:
            //Determine driver to be used
            sDriverName = Vars.os_Name.toLowerCase().contains("win") ? "chromedriver-win.exe"
                    : (Vars.os_Name.toLowerCase().contains("mac") ? "chromedriver-mac" : "chromedriver-lnx");

            //Initializing Driver
            System.setProperty("webdriver.chrome.driver", Vars.os_PathRef + sDriverName);
            DesireCaps = DesiredCapabilities.chrome();
            driver = new ChromeDriver(DesireCaps);
            break;
        case IE:
            //Determine driver to be used
            System.setProperty("webdriver.ie.driver", Vars.os_PathRef + "IEDriverServer-win.exe");
            DesireCaps = Vars.os_Name.toLowerCase().contains("win") ? DesiredCapabilities.internetExplorer()
                    : null;
            if (DesireCaps == null) {
                throw new Exception("Invalid OS for browser.");
            }

            //Create instance
            driver = new InternetExplorerDriver(DesireCaps);
            break;
        case OPERA:
            //Determine driver to be used
            sDriverName = Vars.os_Name.toLowerCase().contains("win") ? "operadriver-win.exe"
                    : (Vars.os_Name.toLowerCase().contains("mac") ? "operadriver-mac" : "operadriver-lnx");

            //Initializing Driver
            System.setProperty("webdriver.chrome.driver", Vars.os_PathRef + sDriverName);
            driver = new ChromeDriver();
            break;
        case SAFARI:
            //Initializing Driver
            driver = new SafariDriver();
            break;
        case PHANTOMJS:
            //Determine driver to be used
            sDriverName = Vars.os_Name.toLowerCase().contains("win") ? "phantomjs-win.exe"
                    : (Vars.os_Name.toLowerCase().contains("mac") ? "phantomjs-mac" : "phantomjs-lnx");

            //Initializing Driver
            DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
                    Vars.os_PathRef + sDriverName);
            driver = new PhantomJSDriver();
            break;
        default:
            throw new Exception("Unsupported browser.");
        }

        //Getting additional browser information
        Vars.ts_BHandler = driver.getWindowHandle();

    } catch (Exception e) {
        frmError("creating a browser instance (" + bBrowserName + ")", e.getMessage(), severity.HIGH);
    }
    return driver;
}

From source file:selenium.WebDriverBuilder.java

public EventFiringWebDriver getFirefoxDriver(Site site) {
    FirefoxProfile ffp = new FirefoxProfile();
    ffp.setPreference("general.useragent.override", site.getUserAgent());
    DesiredCapabilities caps = DesiredCapabilities.firefox();
    caps.setJavascriptEnabled(true);//from   w  ww .  j  a  v  a 2 s. co m
    caps.setCapability(FirefoxDriver.PROFILE, ffp);
    caps.setCapability("takesScreenshot", true);
    // User Name & Password Settings
    webDriver = new FirefoxDriver(caps);
    if (site.getViewPortHeight() > 0 && site.getViewPortWidth() > 0) {
        Dimension s = new Dimension(site.getViewPortWidth(), site.getViewPortHeight());
        webDriver.manage().window().setSize(s);
    } else {
        webDriver.manage().window().maximize();
    }
    webDriver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    driver = new EventFiringWebDriver(webDriver);
    EventHandler handler = new EventHandler();
    driver.register(handler);
    return driver;
}

From source file:sfp.gov.py.core.FFDriver.java

License:Open Source License

/**
 * https://www.seleniumeasy.com/selenium-tutorials/how-to-download-a-file-with-webdriver
 *///from   ww  w . j  av a2s  . c o  m
private static void loadCapabilities() {
    profile = new FirefoxProfile();
    capability = DesiredCapabilities.firefox();
    capability.setCapability(FirefoxDriver.PROFILE, profile);
    capability.setPlatform(Platform.WIN10);
    capability.setVersion("51.0.1");
    capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    profile.setPreference("browser.download.folderList", 2);
    profile.setPreference("browser.download.manager.showWhenStarting", false);
    profile.setPreference("browser.download.dir", properties.getProperty("app.download-path"));
    profile.setPreference("browser.helperApps.neverAsk.openFile", String.join(",", mimeTypes));
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk", String.join(",", mimeTypes));
    profile.setPreference("browser.helperApps.alwaysAsk.force", false);
    profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
    profile.setPreference("browser.download.manager.focusWhenStarting", false);
    profile.setPreference("browser.download.manager.useWindow", false);
    profile.setPreference("browser.download.manager.showAlertOnComplete", false);
    profile.setPreference("browser.download.manager.closeWhenDone", false);
}