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:FirefoxConsoleExport.java

License:Open Source License

public FirefoxConsoleExport(int port) throws IOException {
    super(port);/*from  w  w  w .  ja v a2 s  . c  o  m*/
    start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
    ClassLoader classLoader = FirefoxConsoleExport.class.getClassLoader();
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    FirefoxProfile fp = new FirefoxProfile();
    File extensionToInstall = new File(classLoader.getResource("firebug-2.0.16-fx.xpi").getFile());
    File extension2 = new File(classLoader.getResource("consoleExport-0.5b5.xpi").getFile());

    fp.addExtension(extensionToInstall);
    fp.addExtension(extension2);

    fp.setPreference("extensions.firebug.currentVersion", "2.0");
    fp.setPreference("extensions.firebug.console.enableSites", "true");
    fp.setPreference("extensions.firebug.net.enableSites", "true");
    fp.setPreference("extensions.firebug.script.enableSites", "true");
    fp.setPreference("extensions.firebug.allPagesActivation", "on");
    fp.setPreference("extensions.firebug.consoleexport.active", "true");
    fp.setPreference("extensions.firebug.consoleexport.serverURL", "http://127.0.0.1:9999");

    cap.setCapability(FirefoxDriver.PROFILE, fp);
    driver = new FirefoxDriver(cap);

}

From source file:GeneralCookieDriver.java

License:Open Source License

public WebDriver getWebDriver(Browser browser, boolean privateBrowsing) {
    if (browser.equals(Browser.CHROME)) {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();

        if (privateBrowsing) {
            capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
        }/*w ww.java  2 s  . c om*/

        System.setProperty("webdriver.chrome.driver", chromeDriverLocation);

        return new ChromeDriver(capabilities);
    } else if (browser.equals(Browser.FIREFOX)) {
        FirefoxProfile ffp = new FirefoxProfile();

        if (privateBrowsing) {
            ffp.setPreference("browser.privatebrowsing.dont_prompt_on_enter", true);
            ffp.setPreference("browser.privatebrowsing.autostart", true);
        }

        DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability(FirefoxDriver.PROFILE, ffp);
        return new FirefoxDriver(capabilities);
    } else if (browser.equals(Browser.IE)) {
        System.setProperty("webdriver.ie.driver", ieDriverLocation);

        DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

        if (privateBrowsing) {
            System.err.println("Launching into browsing mode is not supported in IE.");
            return null;
        }

        return new InternetExplorerDriver();
    } else if (browser.equals(Browser.SAFARI)) {
        if (privateBrowsing) {
            System.out
                    .println("WARNING: Selenium does not support launching into Safari private browsing mode.");
            System.out
                    .println("         You will be given 10 seconds to transition into the private browsing ");
            System.out.println("         mode before the tests begin!");
        }

        return new SafariDriver();
    }

    return null;
}

From source file:com.atanas.kanchev.testframework.selenium.driverfactory.DesiredCapsFactory.java

License:Apache License

/**
 * <p>setCustomFirefoxProfile.</p>
 *
 * @param firefoxProfile a {@link org.openqa.selenium.firefox.FirefoxProfile} object.
 * @return a {@link org.openqa.selenium.remote.DesiredCapabilities} object.
 *//*from  w  w w. ja v  a 2  s. c o  m*/
public DesiredCapabilities setCustomFirefoxProfile(FirefoxProfile firefoxProfile) {

    if (firefoxProfile != null) {
        if (caps == null)
            caps = DesiredCapabilities.firefox();
        caps.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
    } else
        throw new IllegalArgumentException("Null FirefoxProfile argument");

    return caps;
}

From source file:com.autocognite.selenium.lib.SeleniumWebUiDriver.java

License:Apache License

public WebDriver getFirefoxDriver() {
    this.setAppTitle(getRunConfig().get(UiAutomator.WINDOW_NAME_FIREFOX));
    capabilities = getFireFoxCapabilitiesSkeleton();
    //driver = new FirefoxDriver(capabilities);
    FirefoxProfile profile = new FirefoxProfile();
    profile.setEnableNativeEvents(true);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    setCapabilities(capabilities);//from ww  w. jav  a 2 s. c o m
    return new FirefoxDriver(capabilities);
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build a webDriver based on the passed in browser request
 *
 * @param browser//from   www  .ja  v a2 s.  co m
 * @return WebDriver
 * @throws MalformedURLException
 */
private static WebDriver buildWebDriver(String browserName) {
    DesiredCapabilities capability = null;
    BrowserType browserType = BrowserType.getBrowserTypeFromString(browserName);
    switch (browserType) {
    case MARIONETTE:
        FirefoxProfile ffProfile = null;
        ffProfile = new FirefoxProfile();
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        cap.setCapability("firefox_profile", ffProfile);
        cap.setCapability("handlesAlerts", true);
        sysEnv = System.getenv("webdriver.firefox.marionette");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "geckodriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.firefox.marionette in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.firefox.marionette", sysEnv);
            }
        }
        return new MarionetteDriver(capability);
    case FIREFOX_DRIVER:
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        firefoxProfile.setAssumeUntrustedCertificateIssuer(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        return new FirefoxDriver(capability);
    case CHROME_DRIVER:
        sysEnv = System.getenv("webdriver.chrome.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "chromedriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.chrome.driver in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.chrome.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments(new String[] { "--allow-running-insecure-content" });
        options.addArguments(new String[] { "--ignore-certificate-errors" });
        options.addArguments(new String[] { "--enable-npapi" });
        options.addArguments(new String[] { "--disable-extensions" });
        options.addArguments(new String[] { "--start-maximized" });
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability(ChromeOptions.CAPABILITY, options);
        return new ChromeDriver(capability);
    case INTERNET_EXPLORER:
        sysEnv = System.getenv("webdriver.ie.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "IEDriverServer.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.ie.driver in system environment variables and restart the PC");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.ie.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.internetExplorer();
        capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        capability.setCapability("ignoreProtectedModeSettings", true);
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability("ignoreZoomSetting", true);
        capability.setCapability("nativeEvents", true);
        capability.setCapability("ie.ensureCleanSession", true);
        return new InternetExplorerDriver(capability);
    case SAFARI:
        capability = DesiredCapabilities.safari();
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ensureCleanSession", true);
        capability.setJavascriptEnabled(true);
        return new SafariDriver(capability);
    /*        case OPERA_DRIVER:
    capability = DesiredCapabilities.opera();
    capability.setCapability("opera.host", "127.0.0.1");
    return new OperaDriver();
     */
    case EDGE:
        capability = DesiredCapabilities.edge();
        EdgeOptions option = new EdgeOptions();
        capability.setCapability("edgeOptions", option);
        return new EdgeDriver(capability);
    default:
        log.info(
                "Currenty support is there for Chrome, Firefox, Firefox Marionette, Internet Explorer, Edge, Safari & Opera. Support is not there for "
                        + browserName);
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProf = new FirefoxProfile();
        firefoxProf.setAcceptUntrustedCertificates(true);
        firefoxProf.setEnableNativeEvents(true);
        firefoxProf.setAssumeUntrustedCertificateIssuer(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProf);
        return new FirefoxDriver(capability);
    }
}

From source file:com.chtr.tmoauto.webui.CommonFunctions.java

License:Open Source License

/**
 * This method build a RemoteWebDriver based on the passed in browser request
 *
 * @param browser/*from w  ww  .  j  a  v a 2  s.  co m*/
 * @return RemoteWebDriver
 *
 */
private static RemoteWebDriver buildRemoteWebDriver(String browserName) {
    DesiredCapabilities capability = null;
    BrowserType browserType = BrowserType.getBrowserTypeFromString(browserName);
    switch (browserType) {
    case MARIONETTE:
        FirefoxProfile ffProfile = null;
        ffProfile = new FirefoxProfile();
        ffProfile.setAcceptUntrustedCertificates(true);
        ffProfile.setAssumeUntrustedCertificateIssuer(false);
        DesiredCapabilities cap = DesiredCapabilities.firefox();
        cap.setCapability("marionette", true);
        cap.setCapability("firefox_profile", ffProfile);
        cap.setCapability("handlesAlerts", true);
        sysEnv = System.getenv("webdriver.firefox.marionette");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "geckodriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.firefox.marionette in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.firefox.marionette", sysEnv);
            }
        }
        return new MarionetteDriver(capability);
    case FIREFOX_DRIVER:
        capability = DesiredCapabilities.firefox();
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new FirefoxDriver(capability);
    case CHROME_DRIVER:
        sysEnv = System.getenv("webdriver.chrome.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "chromedriver.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.chrome.driver in system environment variables and restart the PC OR copy all your webdrivers under 'C:/selenium' location");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.chrome.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.chrome();
        ChromeOptions options = new ChromeOptions();
        options.addArguments(new String[] { "--allow-running-insecure-content" });
        options.addArguments(new String[] { "--ignore-certificate-errors" });
        options.addArguments(new String[] { "--enable-npapi" });
        options.addArguments(new String[] { "--disable-extensions" });
        options.addArguments(new String[] { "--start-maximized" });
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability(ChromeOptions.CAPABILITY, options);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new ChromeDriver(capability);
    case INTERNET_EXPLORER:
        sysEnv = System.getenv("webdriver.ie.driver");
        if (sysEnv == null) {
            sysEnv = findFileName("C:/apps/selenium", "IEDriverServer.exe", FileSearchType.File);
            if (sysEnv == null) {
                log.info(
                        "Please set the webdriver.ie.driver in system environment variables and restart the PC");
                throw new RuntimeException("Failed to instantiate a WebDriver instance for " + browserName);
            } else {
                System.setProperty("webdriver.ie.driver", sysEnv);
            }
        }
        capability = DesiredCapabilities.internetExplorer();
        capability.setCapability("ignoreProtectedModeSettings", true);
        String browserVersion = capability.getVersion();
        if (browserVersion != null && browserVersion.equals("10")) {
            capability.setPlatform(Platform.WINDOWS);
            capability.setVersion(browserVersion);
        } else if (browserVersion != null && browserVersion.equals("11")) {
            capability.setPlatform(Platform.WIN8_1);
            capability.setVersion(browserVersion);
        }
        capability.setBrowserName("internet explorer");
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new InternetExplorerDriver(capability);
    case SAFARI:
        capability = DesiredCapabilities.safari();
        capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capability.setCapability("ensureCleanSession", true);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(null);
        return new SafariDriver(capability);
    /*         case OPERA_DRIVER:
    capability = DesiredCapabilities.opera();
    capability.setCapability("opera.profile", "/test");
    return new OperaDriver();
    */
    case EDGE:
        capability = DesiredCapabilities.edge();
        EdgeOptions option = new EdgeOptions();
        capability.setCapability("edgeOptions", option);
        return new EdgeDriver(capability);
    default:
        log.info(
                "Currenty support is there for Chrome, Firefox, Firefox Marionette, Internet Explorer, Edge, Safari & Opera. Support is not there for "
                        + browserName);
        capability = DesiredCapabilities.firefox();
        firefoxProfile = new FirefoxProfile();
        firefoxProfile.setAcceptUntrustedCertificates(true);
        firefoxProfile.setEnableNativeEvents(true);
        capability.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        capability.setPlatform(capability.getPlatform());
        capability.setVersion(capability.getVersion());
        return new FirefoxDriver(capability);
    }
}

From source file:com.comcast.magicwand.spells.web.firefox.FirefoxPhoenixDriver.java

License:Apache License

/**
 * {@inheritDoc}/*from   ww  w.  ja v a 2  s .  c  om*/
 */
public boolean verify(PhoenixDriverIngredients i) {
    boolean rv = false;

    if (this.verifyIngredients(i)) {
        rv = true;
        ProfilesIni allProfiles = this.createProfilesIni();
        FirefoxProfile fp = allProfiles.getProfile("default");

        DesiredCapabilities dc = i.getDriverCapabilities();

        if (null == dc.getCapability(FirefoxDriver.PROFILE)) {
            dc.setCapability(FirefoxDriver.PROFILE, fp);
        }

        this.webDriver = createDriver(dc);
    }

    return rv;
}

From source file:com.consol.citrus.selenium.client.WebClient.java

License:Apache License

private WebDriver createLocalWebDriver(BrowserTypeEnum browserType) {
    switch (browserType) {
    case FIREFOX:
        DesiredCapabilities defaults = DesiredCapabilities.firefox();
        defaults.setCapability(FirefoxDriver.PROFILE, createFireFoxProfile());
        return new FirefoxDriver(defaults);
    case INTERNET_EXPLORER:
        return new InternetExplorerDriver();
    case CHROME://  w  ww  .  j ava 2s  . co  m
        return new ChromeDriver();
    default:
        HtmlUnitDriver hud = new HtmlUnitDriver(BrowserVersion.FIREFOX_38);
        hud.setJavascriptEnabled(true);
        return hud;
    }
}

From source file:com.consol.citrus.selenium.client.WebClient.java

License:Apache License

private RemoteWebDriver createRemoteWebDriver(BrowserTypeEnum browserType, String serverAddress)
        throws MalformedURLException {
    switch (browserType) {
    case FIREFOX:
        DesiredCapabilities defaultsFF = DesiredCapabilities.firefox();
        defaultsFF.setCapability(FirefoxDriver.PROFILE, createFireFoxProfile());
        return new RemoteWebDriver(new URL(serverAddress), defaultsFF);
    case INTERNET_EXPLORER:
        DesiredCapabilities defaultsIE = DesiredCapabilities.internetExplorer();
        defaultsIE.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new RemoteWebDriver(new URL(serverAddress), defaultsIE);
    default:/*from  w  w  w .  j av  a  2s. c o  m*/
        DesiredCapabilities defaults = DesiredCapabilities.chrome();
        defaults.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        return new RemoteWebDriver(new URL(serverAddress), defaults);
    }
}

From source file:com.consol.citrus.selenium.endpoint.SeleniumBrowser.java

License:Apache License

/**
 * Creates local web driver.//from  w w w.ja  v a2  s.com
 * @param browserType
 * @return
 */
private WebDriver createLocalWebDriver(String browserType) {
    switch (browserType) {
    case BrowserType.FIREFOX:
        FirefoxProfile firefoxProfile = getEndpointConfiguration().getFirefoxProfile();

        /* set custom download folder */
        firefoxProfile.setPreference("browser.download.dir", temporaryStorage.toFile().getAbsolutePath());

        DesiredCapabilities defaults = DesiredCapabilities.firefox();
        defaults.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
        return new FirefoxDriver(defaults);
    case BrowserType.IE:
        return new InternetExplorerDriver();
    case BrowserType.EDGE:
        return new EdgeDriver();
    case BrowserType.SAFARI:
        return new SafariDriver();
    case BrowserType.CHROME:
        return new ChromeDriver();
    case BrowserType.GOOGLECHROME:
        return new ChromeDriver();
    case BrowserType.HTMLUNIT:
        BrowserVersion browserVersion = null;
        if (getEndpointConfiguration().getVersion().equals("FIREFOX")) {
            browserVersion = BrowserVersion.FIREFOX_45;
        } else if (getEndpointConfiguration().getVersion().equals("INTERNET_EXPLORER")) {
            browserVersion = BrowserVersion.INTERNET_EXPLORER;
        } else if (getEndpointConfiguration().getVersion().equals("EDGE")) {
            browserVersion = BrowserVersion.EDGE;
        } else if (getEndpointConfiguration().getVersion().equals("CHROME")) {
            browserVersion = BrowserVersion.CHROME;
        }

        HtmlUnitDriver htmlUnitDriver;
        if (browserVersion != null) {
            htmlUnitDriver = new HtmlUnitDriver(browserVersion);
        } else {
            htmlUnitDriver = new HtmlUnitDriver();
        }
        htmlUnitDriver.setJavascriptEnabled(getEndpointConfiguration().isJavaScript());
        return htmlUnitDriver;
    default:
        throw new CitrusRuntimeException("Unsupported local browser type: " + browserType);
    }
}