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.testmax.util.JavaScriptUtl.java

License:CDDL license

public WebDriver initWebDriverDriver(String browser) {

    this.browser = browser;

    File file = null;//from   w  w w .  j av  a2s. c om
    if (browser == null || browser.isEmpty()) {
        browser = "firefox";
    }
    try {
        String driver_path = "";
        if (browser.equalsIgnoreCase("chrome")) {
            if (TestEngine.suite != null) {
                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);
            }
            WmLog.printMessage("Chrome Driver Path=" + file.getAbsolutePath());
            System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
            if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                file = new File(ConfigLoader.getWmRoot() + "/lib/chromedriver_mac");
                System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
                DesiredCapabilities capability = DesiredCapabilities.chrome();
                capability.setCapability("platform", Platform.ANY);
                capability.setCapability("binary", "/Application/chrome"); //for linux
                driver = new ChromeDriver(capability);

            } else {
                driver = new ChromeDriver();
            }
        } else if (browser.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);
            }
            WmLog.printMessage("##### IE DRIVER PATH=" + file.getAbsolutePath());
            System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
            driver = new InternetExplorerDriver();
            maxTimeToWait = maxTimeToWait * 5;

        } else if (browser.equalsIgnoreCase("firefox")) {
            DesiredCapabilities capability = DesiredCapabilities.firefox();
            LoggingPreferences prefs = new LoggingPreferences();
            prefs.enable(LogType.BROWSER, Level.ALL);
            capability.setCapability(CapabilityType.LOGGING_PREFS, prefs);

            if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                //DesiredCapabilities capability = DesiredCapabilities.firefox();
                capability.setCapability("platform", Platform.ANY);
                capability.setCapability("binary", "/Application/firefox"); //for linux

                driver = new FirefoxDriver(capability);

            } else {

                driver = new FirefoxDriver(capability);
            }
        } else if (browser.equalsIgnoreCase("safari")) {

            if (System.getProperty("os.name").toLowerCase().contains("mac")) {
                WmLog.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
                WmLog.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 (browser.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();

        }
        driver.manage().timeouts().implicitlyWait(maxTimeToWait, TimeUnit.SECONDS);

    } catch (Exception e) {

        WmLog.printMessage("******** FAILED to launch browser=" + this.browser + " :" + e.getMessage());
        e.printStackTrace();
    }

    return driver;
}

From source file:com.thebodgeitstore.selenium.tests.FunctionalITCase.java

License:Apache License

public void setUp() throws Exception {
    Properties properties = new Properties();
    properties.load(new FileReader("local.properties"));
    String target = properties.getProperty("zap.targetApp");
    if (target != null && target.length() > 0) {
        // Theres an override
        setSite(target);//from  ww  w.j a v a  2s .co  m
    }

    Proxy proxy = new Proxy();
    String proxyHost = properties.getProperty("zap.proxy.host");
    String proxyPort = properties.getProperty("zap.proxy.port");
    String proxyIP = proxyHost + ":" + proxyPort;
    proxy.setHttpProxy(proxyIP).setFtpProxy(proxyIP).setSslProxy(proxyIP).setNoProxy("");

    // We use firefox as an example here.
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.PROXY, proxy);

    // You could use any webdriver implementation here
    WebDriver driver = new FirefoxDriver(capabilities);

    this.setDriver(driver);
}

From source file:com.thebodgeitstore.selenium.tests.FunctionalZAP.java

License:Apache License

public void setUp() throws Exception {
    String target = System.getProperty("zap.targetApp");
    if (target != null && target.length() > 0) {
        // Theres an override
        setSite(target);/*from  w w w . j a v a 2s . co m*/
    }

    Proxy proxy = new Proxy();
    proxy.setHttpProxy(System.getProperty("zap.proxy"));

    // We use firefox as an example here.
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(CapabilityType.PROXY, proxy);

    // You could use any webdriver implementation here
    WebDriver driver = new FirefoxDriver(capabilities);
    this.setDriver(driver);
}

From source file:com.thoughtworks.selenium.corerunner.Main.java

License:Apache License

public static void main(String[] args) {
    //    java -jar selenium-server-standalone-<version-number>.jar -htmlSuite "*firefox"
    //    "http://www.google.com" "c:\absolute\path\to\my\HTMLSuite.html"
    //    "c:\absolute\path\to\my\results.html"
    if (args.length < 5) {
        throw new RuntimeException("Not enough arguments");
    }//from  ww w .  ja v a2s.  c o m
    if (!"-htmlSuite".equals(args[0])) {
        throw new RuntimeException("Apparently not running a test suite");
    }

    WebDriver driver;
    switch (args[1]) {
    case "*chrome":
    case "*firefox":
    case "*firefoxproxy":
    case "*firefoxchrome":
    case "*pifirefox":
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability(MARIONETTE, false);
        driver = new FirefoxDriver(caps);
        break;

    case "*iehta":
    case "*iexplore":
    case "*iexploreproxy":
    case "*piiexplore":
        driver = new InternetExplorerDriver();
        break;

    case "*googlechrome":
        driver = new ChromeDriver();
        break;

    case "*MicrosoftEdge":
        driver = new EdgeDriver();
        break;

    case "*opera":
    case "*operablink":
        driver = new OperaDriver();
        break;

    case "*safari":
    case "*safariproxy":
        driver = new SafariDriver();
        break;

    default:
        throw new RuntimeException("Unrecognized browser: " + args[1]);
    }

    try {
        Results results = new Results();
        CoreTest test = new CoreTest(args[3]);
        test.run(results, driver, new WebDriverBackedSelenium(driver, args[2]));
    } finally {
        driver.quit();
    }
}

From source file:com.thoughtworks.selenium.SeleneseTestNgHelperVir.java

License:Apache License

/**
 * Start browser session./*from w w w .  ja  va  2 s  .c  o m*/
 * 
 * @param browserString
 *            the browser string
 */
public final void startBrowserSession(final String browserString) {

    DesiredCapabilities capabilities = getWebDriverCapabilities();
    WebDriver driver;
    if (browserString.contains("chrome") || browserString.contains("Chrome")) {
        driver = new ChromeDriver();

    } else if (browserString.contains("safari")) {

        DesiredCapabilities.safari();
        driver = new SafariDriver(capabilities);

    } else if (browserString.contains("iexplore")) {

        DesiredCapabilities.internetExplorer();
        capabilities.setJavascriptEnabled(true);
        driver = new InternetExplorerDriver(capabilities);

    } else if (browserString.contains("firefox")) {
        FirefoxProfile profile = getDefaultProfile();
        profile.setEnableNativeEvents(true);
        driver = new FirefoxDriver(profile);

    } else if (browserString.contains("opera")) {

        DesiredCapabilities.opera();
        driver = new OperaDriver(capabilities);
    } else {
        getLog().info("Unsupported browser type passed " + browserString);
        throw new AssertionError("Unsupported Browser");
    }

    setDriver(driver);
    if (getSeleniumInstances().isEmpty()) {
        putSeleniumInstances("default", driver);
    } else {
        putSeleniumInstances(getSeleniumInstanceName(), driver);
    }
}

From source file:com.thoughtworks.webanalyticsautomation.scriptrunner.helper.WebDriverScriptRunnerHelper.java

License:Open Source License

private void instantiateFireFoxDriver(DesiredCapabilities capabilities) {
    driver = new FirefoxDriver(capabilities);
    driver.get(BASE_URL);
}

From source file:com.twiceagain.mywebdriver.driver.web.Drivers.java

License:Open Source License

/**
 * Get a driver with the specified config.
 *
 * @param config/*from   w w w . ja v a 2s .co  m*/
 * @return
 */
public static WebDriver getDriver(final Config config) {
    WebDriver wd;
    try {
        // Local firefox instance
        if (!config.useGrid) {
            // LoadGeckodriver if needed
            Config.installGeckoDriver();
            // Set geckodriver full absolute path
            System.setProperty("webdriver.gecko.driver", Config.geckodriverPath);
            wd = new FirefoxDriver(config.getDesiredCapabilities());
            // Grid instance
        } else {

            wd = new RemoteWebDriver(new URL(config.gridUrl), config.getDesiredCapabilities());

        }
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, null, ex);
        return null;
    }

    // Adjust window size
    wd.manage().window().setSize(new Dimension(config.width, config.height));
    return wd;
}

From source file:com.vilt.minium.script.impl.FirefoxDriverFactory.java

License:Apache License

@Override
public WebDriver create(DesiredCapabilities capabilities) {
    return new FirefoxDriver(capabilities);
}

From source file:com.watchrabbit.crawler.driver.factory.FirefoxWebDriverFactory.java

License:Apache License

@Override
public synchronized RemoteWebDriver produceDriver() {
    LOGGER.debug("Returning new driver");
    if (drivers.isEmpty()) {
        LOGGER.debug("Creating new driver");
        FirefoxProfile profile = new FirefoxProfile();
        profile.setAcceptUntrustedCertificates(true);
        RemoteWebDriver ff = new FirefoxDriver(profile);
        return ff;
    } else {//from  w ww . j a  va 2  s  .  co  m
        LOGGER.debug("Returning {} driver from pool", drivers.peek().getWindowHandle());
        return drivers.poll();
    }
}

From source file:com.worldline.easycukes.selenium.WebDriverFactory.java

License:Open Source License

/**
 * Creates a new Firefox driver instance
 *
 * @return a FirefoxDriver instance//from w  ww  .  jav  a 2s  .  c  o  m
 */
private static WebDriver newLocalFirefoxDriver() {
    return new FirefoxDriver(firefoxCapabilities());
}