Example usage for org.openqa.selenium.firefox FirefoxDriver FirefoxDriver

List of usage examples for org.openqa.selenium.firefox FirefoxDriver FirefoxDriver

Introduction

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

Prototype

public FirefoxDriver(FirefoxDriverService service) 

Source Link

Usage

From source file:com.sios.stc.coseng.util.Run.java

License:Open Source License

public synchronized WebDriver getWebDriver(final String testName) throws MalformedURLException {

    WebDriver driver = null;//from w  ww .  ja va 2 s.  co  m

    if (testName != null) {

        for (final TestParam p : param.testParam) {
            if (p.getTestName().equals(testName)) {

                // DesiredCapabilities
                // https://code.google.com/p/selenium/wiki/DesiredCapabilities

                // !! It is *not* necessary to start *any* of the browser driver
                // profiles to start 'private/icognito' as each new driver
                // instance starts with a *fresh* profile that does not persist
                // after the driver is quit. !!

                if (p.getBrowser().equals(Browser.FIREFOX)) {
                    final FirefoxProfile profile = new FirefoxProfile();
                    final DesiredCapabilities dc = DesiredCapabilities.firefox();
                    if (p.getPlatform().equals(Platform.LINUX)) {
                        // Explicitly enable native events(this is mandatory on Linux system,
                        // since they are not enabled by default.
                        profile.setEnableNativeEvents(true);
                        dc.setPlatform(p.getPlatform());
                        dc.setCapability(Common.BROWSER_CAPABILITY_FIREFOX_PROFILE, profile);
                    }
                    if (p.getSpot().equals(Spot.LOCAL)) {
                        driver = new FirefoxDriver(profile);
                    } else {
                        driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc);
                    }
                } else if (p.getBrowser().equals(Browser.CHROME)) {
                    final DesiredCapabilities dc = DesiredCapabilities.chrome();
                    dc.setPlatform(p.getPlatform());
                    if (p.getSpot().equals(Spot.LOCAL)) {
                        driver = new ChromeDriver();
                    } else {
                        driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc);
                    }
                } else if (p.getBrowser().toString().toLowerCase().startsWith("ie")) {
                    final DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
                    dc.setBrowserName(Common.BROWSER_NAME_INTERNET_EXPLORER);
                    dc.setPlatform(p.getPlatform());
                    // IE8 and newer; Make sure
                    // HKEY_USERS\.Default\Software\Microsoft\Internet
                    // Explorer has DWORD TabProcGrowth set 0
                    // Launch separate process in 'private' mode.
                    dc.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
                    dc.setCapability(InternetExplorerDriver.IE_SWITCHES, "-private");
                    //dc.setCapability(InternetExplorerDriver.LOG_FILE,
                    //        "C:/iedriver.log");
                    //dc.setCapability(InternetExplorerDriver.LOG_LEVEL,
                    //        "DEBUG");
                    dc.setCapability(InternetExplorerDriver.NATIVE_EVENTS, true);
                    // dc.setCapability(
                    // InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,
                    // true);

                    // If *is* a specific IE9, IE10, IE11 (not IE) set the version
                    if (!p.getBrowser().equals(Browser.IE)) {
                        dc.setVersion(p.getBrowser().getVersion());
                    }

                    if (p.getSpot().equals(Spot.LOCAL)) {
                        driver = new InternetExplorerDriver();
                    } else {
                        driver = new RemoteWebDriver(new URL(p.getSeleniumGridUrl()), dc);
                    }
                }
            }
            // Collect the driver for quit after tests complete
            if (driver != null) {
                collectDriver(driver);
            }
        }
    }
    return driver;
}

From source file:com.smartqa.webdriver.Browser.java

License:Apache License

/**
 * create FirefoxDriver/*w  w  w.ja  v a2 s . co  m*/
 * 
 * @return FirefoxDriver
 */
public WebDriver getFirefoxDriver() {
    if (firefoxReady) {
        ProfilesIni allProfiles = new ProfilesIni();
        FirefoxProfile fp = allProfiles.getProfile("default");
        //         fp.setPreference("capability.policy.policynames", "strict") ;
        //         fp.setPreference("capability.policy.strict.Window.alert", "noAccess") ;
        //         fp.setPreference("capability.policy.strict.Window.confirm", "noAccess") ;
        //         fp.setPreference("capability.policy.strict.Window.prompt", "noAccess") ;
        return new FirefoxDriver(fp);
    }

    return null;
}

From source file:com.smash.revolance.ui.server.BrowserSteps.java

License:Open Source License

private void instanciateFirefoxDriver() {
    DesiredCapabilities cfg = DesiredCapabilities.firefox();
    cfg.setJavascriptEnabled(true);/*from ww w  . jav  a2s. co  m*/
    browser = new FirefoxDriver(cfg);
    browser.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.sonar.it.jenkins.orchestrator.JenkinsOrchestrator.java

License:Open Source License

public void start() {
    if (started.getAndSet(true)) {
        throw new IllegalStateException("Jenkins is already started");
    }/*w  ww.j  a  v  a 2s .c o  m*/

    int port = config.getInt("jenkins.container.port", 0);
    if (port <= 0) {
        port = NetworkUtils.getNextAvailablePort();
    }
    distribution.setPort(port);
    FileSystem fileSystem = config.fileSystem();
    ServerInstaller serverInstaller = new ServerInstaller(fileSystem);
    server = serverInstaller.install(distribution);
    server.setUrl(String.format("http://localhost:%d", port));

    jenkinsWrapper = new JenkinsWrapper(server, config, fileSystem.javaHome(), port);
    jenkinsWrapper.start();

    FirefoxProfile profile = new FirefoxProfile();
    // Disable native events on all OS to avoid strange characters when using sendKeys
    profile.setEnableNativeEvents(false);
    driver = new FirefoxDriver(profile);

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get(server.getUrl());

    // Fix window size for having reproducible test behavior
    driver.manage().window().setPosition(new Point(20, 20));
    driver.manage().window().setSize(new Dimension(1024, 768));
    try {
        cli = new CLI(new URL(server.getUrl()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.surevine.alfresco.space.webdriver.AlfrescoWebDriverTestCase.java

License:Open Source License

@Before
public void openBrowserAndLogin() {
    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile profile = allProfiles.getProfile("selenium");

    // This looks counter-intuitive, but it works there has been lots of talk on the google groups about
    // the trusting and otherwise of ssl certificates.
    profile.setAcceptUntrustedCertificates(false);
    FirefoxDriver ffd = new FirefoxDriver(profile);

    casLoginPage = PageFactory.initElements(ffd, CasLogin.class);
    casLoginPage.open("http://79.125.19.164/share");
    space = casLoginPage.login("admin", "password");
}

From source file:com.surevine.alfresco.space.webdriver.TestSpaceDashboard.java

License:Open Source License

@Before
public void openTheBrowser() {

    ProfilesIni allProfiles = new ProfilesIni();
    FirefoxProfile profile = allProfiles.getProfile("selenium");
    // This looks counter-intuitive, but it works there has been lots of talk on the google groups about
    // the trusting and otherwise of ssl certificates.
    profile.setAcceptUntrustedCertificates(false);
    FirefoxDriver ffd = new FirefoxDriver(profile);

    casLoginPage = PageFactory.initElements(ffd, CasLogin.class);
    casLoginPage.open("http://79.125.19.164/share");
    space = casLoginPage.login("admin", "password");
}

From source file:com.tascape.qa.th.webui.comm.Firefox.java

License:Apache License

public Firefox(boolean enableFirebug) throws Exception {
    FirefoxProfile profile;/*from   w  w  w  .j a va 2 s.  c  om*/

    ProfilesIni profileIni = new ProfilesIni();
    String profileName = sysConfig.getProperty(SYSPROP_FF_PROFILE_NAME);
    if (profileName != null) {
        LOG.debug("Load Firefox profile named as {}", profileName);
        profile = profileIni.getProfile(profileName);
    } else {
        LOG.debug("Load Firefox profile named as {}", DEFAULT_FF_PROFILE_NAME);
        profile = profileIni.getProfile(DEFAULT_FF_PROFILE_NAME);
    }
    if (profile == null) {
        throw new Exception("Cannot find Firefox profile");
    }

    profile.setPreference("app.update.enabled", false);
    profile.setEnableNativeEvents(false);
    profile.setAcceptUntrustedCertificates(true);
    profile.setAssumeUntrustedCertificateIssuer(false);
    profile.setPreference("dom.max_chrome_script_run_time", 0);
    profile.setPreference("dom.max_script_run_time", 0);
    if (enableFirebug) {
        this.firebug = new Firebug();
        this.firebug.updateProfile(profile);
    }
    long end = System.currentTimeMillis() + 180000;
    while (System.currentTimeMillis() < end) {
        try {
            super.setWebDriver(new FirefoxDriver(profile));
            break;
        } catch (org.openqa.selenium.WebDriverException ex) {
            String msg = ex.getMessage();
            LOG.warn(msg);
            if (!msg.contains("Unable to bind to locking port 7054 within 45000 ms")) {
                throw ex;
            }
        }
    }
}

From source file:com.technophobia.webdriver.substeps.runner.DefaultWebDriverFactory.java

License:Open Source License

public WebDriver createWebDriver() {

    final WebDriver webDriver;

    switch (configuration.driverType()) {
    case FIREFOX: {
        final DesiredCapabilities firefoxCapabilities = DesiredCapabilities.firefox();

        setNetworkCapabilities(firefoxCapabilities);

        setLoggingPreferences(firefoxCapabilities);

        webDriver = new FirefoxDriver(firefoxCapabilities);
        break;//from   w w  w  .ja va2 s. c om

    }
    case HTMLUNIT: {
        final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_38);
        htmlUnitDriver.setJavascriptEnabled(!configuration.isJavascriptDisabledWithHTMLUnit());

        // Run via a proxy - firstly try deprecated HTML unit only
        // properties
        final String htmlunitProxyHost = configuration.getHtmlUnitProxyHost();
        if (StringUtils.isNotEmpty(htmlunitProxyHost)) {
            final int htmlunitProxyPort = configuration.getHtmlUnitProxyPort();
            htmlUnitDriver.setProxy(htmlunitProxyHost, htmlunitProxyPort);
        }
        // Run via a proxy - secondly new network proxy settings
        final String proxyHost = configuration.getNetworkProxyHost();
        if (StringUtils.isNotEmpty(proxyHost)) {
            final int proxyPort = configuration.getNetworkProxyPort();
            htmlUnitDriver.setProxy(proxyHost, proxyPort);
        }

        setDriverLocale(htmlUnitDriver);

        webDriver = htmlUnitDriver;
        break;

    }
    case CHROME: {

        String preset = System.getProperty("webdriver.chrome.driver");

        if (preset == null) {
            String driverPath = configuration.getChromeDriverPath();
            Assert.assertNotNull(
                    "Chromedriver path not set as a -Dwebdriver.chrome.driver parameter or in config",
                    driverPath);
            System.setProperty("webdriver.chrome.driver", driverPath);
        }

        final DesiredCapabilities chromeCapabilities = DesiredCapabilities.chrome();
        setNetworkCapabilities(chromeCapabilities);

        setLoggingPreferences(chromeCapabilities);

        webDriver = new ChromeDriver(chromeCapabilities);
        break;

    }
    case IE: {

        // apparently this is required to get around some IE security
        // restriction.
        final DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                true);

        LOG.warn("Using IE Webdriver with IGNORING SECURITY DOMAIN");

        setNetworkCapabilities(ieCapabilities);
        webDriver = new InternetExplorerDriver(ieCapabilities);
        break;
    }
    default: {
        throw new IllegalArgumentException("unknown driver type " + configuration.driverType());
    }
    }

    webDriver.manage().window().maximize();

    return webDriver;

}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

@Before
public synchronized void setUp() throws Exception {
    //set default driver

    if (this.isMultiThreaded) {
        this.libs = null;
        this.createLogFile();
        this.varmap = BaseHandler.threadData.get(threadIndex);
        if (this.libs == null || this.libs.isEmpty()) {
            this.libs = this.parseTagLib();
        }//from  w  ww. j av a2 s .  c  o m

    } else {
        this.libs = this.parseTagLib();
        this.varmap = BaseHandler.getVarMap();
        this.threadIndex = this.varmap.get("datasetIndex");
    }

    this.printMessage("####### SELENIUM TEST STARTED #################");

    this.printMessage("####### Dataset:" + this.varmap.values());

    this.timer = new PrintTime();
    File file = null;
    //driver = new FirefoxDriver();

    v_driver = getDeclaredVariable("driver");
    if (v_driver == null || v_driver.isEmpty()) {
        v_driver = ConfigLoader.getConfig("SELENIUM_DRIVER");
        if (v_driver == null || v_driver.isEmpty()) {
            v_driver = "firefox";
        }
    }
    String driver_path = getDeclaredVariable("driver_path");
    if (v_driver.equalsIgnoreCase("chrome")) {
        if (TestEngine.suite != null) {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : chrome_driver_path);
            if (!file.exists()) {
                String chrome_path = TestEngine.suite.getWorkspace() + TestEngine.suite.getJobname()
                        + "/lib/chromedriver.exe";
                file = new File(chrome_path);
                if (!file.exists()) {
                    file = new File(TestEngine.suite.getWorkspace() + "/lib/chromedriver.exe");
                }
            }
        } else {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : chrome_driver_path);
        }
        this.printMessage("Chrome Driver Path=" + file.getAbsolutePath());
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        //capability.setCapability("chrome.switches", Arrays.asList("--allow-running-insecure-content=true"));
        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            file = new File(ConfigLoader.getWmRoot() + "/lib/chromedriver_mac");
            System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", "/Application/chrome"); //for linux "chrome.switches", "--verbose"
            capability.setCapability("chrome.switches", "--verbose");
            driver = new ChromeDriver(capability);

        } else {
            driver = new ChromeDriver(capability);
        }
    } else if (v_driver.equalsIgnoreCase("ie")) {
        if (is64bit()) {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : ie_driver_path64bit);
        } else {
            file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : ie_driver_path32bit);
        }
        this.printMessage("##### IE DRIVER PATH=" + file.getAbsolutePath());
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        capability.setCapability("acceptSslCerts", true);
        capability.setCapability("platform", Platform.WINDOWS);
        capability.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
        if (is64bit()) {
            capability.setCapability("iedriver-version", "x64_2.41.0");
        }
        //capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
        driver = new InternetExplorerDriver(capability);
        maxTimeToWait = maxTimeToWait * 5;
        this.isIE = true;

    } else if (v_driver.equalsIgnoreCase("firefox")) {

        /*file = new File("firebug-1.8.1.xpi");
        FirefoxProfile firefoxProfile = new FirefoxProfile();
        firefoxProfile.setPreference("security.mixed_content.block_active_content", false);
        firefoxProfile.setPreference("security.mixed_content.block_display_content", true);
        firefoxProfile.setPreference("browser.cache.disk.enable", true);
        firefoxProfile.addExtension(file);
        firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
        driver = new FirefoxDriver(firefoxProfile);
        */
        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            DesiredCapabilities capability = DesiredCapabilities.firefox();
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", "/Application/firefox"); //for linux
            //capability.setCapability("binary", "/ms/dist/fsf/PROJ/firefox/16.0.0/bin/firefox"); //for linux

            //capability.setCapability("binary", "C:\\Program Files\\Mozilla  Firefox\\msfirefox.exe"); //for windows                
            driver = new FirefoxDriver(capability);

        } else {
            //
            driver = new FirefoxDriver();
        }
    } else if (v_driver.equalsIgnoreCase("safari")) {

        if (System.getProperty("os.name").toLowerCase().contains("mac")) {
            this.printMessage("#####STARTING Safri in Mac ####");
            DesiredCapabilities capability = DesiredCapabilities.safari();
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", "/Application/safari"); //for linux
            driver = new SafariDriver(capability);

        } else {
            // Read Instruction for Safari Extension
            //http://rationaleemotions.wordpress.com/2012/05/25/working-with-safari-driver/
            // Get certificate from https://docs.google.com/folder/d/0B5KGduKl6s6-ZGpPZlA0Rm03Nms/edit
            this.printMessage("#####STARTING Safri in Windows ####");
            String safari_install_path = "C:\\Program Files (x86)\\Safari\\";
            DesiredCapabilities capability = DesiredCapabilities.safari();
            capability.setCapability("platform", Platform.ANY);
            capability.setCapability("binary", safari_install_path + "Safari.exe"); //for windows 
            //capability.setCapability(SafariDriver.DATA_DIR_CAPABILITY, "C:\\Program Files (x86)\\Safari\\SafariData");
            //System.setProperty("webdriver.safari.driver", safari_install_path+"SafariDriver.safariextension\\");
            driver = new SafariDriver(capability);

        }
    } else if (v_driver.equalsIgnoreCase("htmlunit")) {
        DesiredCapabilities capability = DesiredCapabilities.htmlUnit();
        capability.setJavascriptEnabled(true);
        //capability.setCapability("browserName","chrome");
        //capability.setBrowserName(BrowserVersion.CHROME);
        driver = new HtmlUnitDriver(capability);

    } else {
        file = new File(driver_path != null && !driver_path.isEmpty() ? driver_path : chrome_driver_path);
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
        driver = new ChromeDriver();
    }

    baseUrl = ConfigLoader.getConfig("BASE_APPLICATION_URL");
    baseUrl = baseUrl.replace("[env]", ConfigLoader.getConfig("QA_TEST_ENV"));
    for (Cookie cookie : driver.manage().getCookies()) {
        printMessage("name=" + cookie.getName());
        printMessage("domain=" + cookie.getDomain());
        printMessage("path=" + cookie.getPath());
        printMessage("value=" + cookie.getValue());
    }
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

    if (this.varmap.get("browserwidth") != null) {
        try {
            browserwidth = new Integer(this.varmap.get("browserwidth"));
        } catch (Exception e) {
            browserwidth = 1020;
        }
    }
    driver.manage().window().setSize(new Dimension(browserwidth, (int) screenSize.getHeight()));
    String removecookie = getDeclaredVariable("removecookie");
    if (this.isEmptyValue(removecookie) || removecookie.equalsIgnoreCase("yes")) {
        driver.manage().deleteAllCookies();
    }
    driver.manage().timeouts().implicitlyWait(maxTimeToWait, TimeUnit.SECONDS);
    driverList.put(this.threadIndex, driver);
    this.resetTestResult();

}

From source file:com.testmax.handler.SeleniumBaseHandler.java

License:CDDL license

private WebDriver initMacDriver() {
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    capability.setCapability("platform", Platform.ANY);
    capability.setCapability("binary", "/Application/firefox"); //for linux
    //capability.setCapability("binary", "/ms/dist/fsf/PROJ/firefox/16.0.0/bin/firefox"); //for linux

    //capability.setCapability("binary", "C:\\Program Files\\Mozilla  Firefox\\msfirefox.exe"); //for windows                
    WebDriver currentDriver = new FirefoxDriver(capability);
    return currentDriver;
}