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:edu.umd.cs.guitar.crawljax.browser.WebDriverBrowserWrapperBuilder.java

License:Open Source License

/**
 * Build a new WebDriver based EmbeddedBrowser.
 *
 * @see EmbeddedBrowserBuilder#buildEmbeddedBrowser(CrawljaxConfigurationReader)
 * @param configuration the configuration object to read the config values from
 * @return the new build WebDriver based embeddedBrowser
 *///from ww  w  .j av a 2  s.co  m
@Override
public EmbeddedBrowser buildEmbeddedBrowser(CrawljaxConfigurationReader configuration) {
    // Retrieve the config values used
    List<String> filterAttributes = configuration.getFilterAttributeNames();
    int crawlWaitReload = configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl();
    int crawlWaitEvent = configuration.getCrawlSpecificationReader().getWaitAfterEvent();

    EmbeddedBrowser internalBrowser;
    // Determine the requested browser type
    switch (configuration.getBrowser()) {
    case firefox:
        if (configuration.getProxyConfiguration() != null) {
            FirefoxProfile profile = new FirefoxProfile();

            profile.setPreference("network.proxy.http", configuration.getProxyConfiguration().getHostname());
            profile.setPreference("network.proxy.http_port", configuration.getProxyConfiguration().getPort());
            profile.setPreference("network.proxy.type",
                    configuration.getProxyConfiguration().getType().toInt());
            profile.setPreference("network.proxy.no_proxies_on", "");
            internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(profile),
                    filterAttributes, crawlWaitReload, crawlWaitEvent);
            break;
        } else {
            internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(),
                    configuration.getFilterAttributeNames(),
                    configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                    configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
            break;
        }
    case ie:

        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new InternetExplorerDriver(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    case chrome:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new ChromeDriver(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    case remote:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withRemoteDriver(configuration.getRemoteHubUrl(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    case htmlunit:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new HtmlUnitDriver(true),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    default:
        internalBrowser = WebDriverBackedEmbeddedBrowser.withDriver(new FirefoxDriver(),
                configuration.getFilterAttributeNames(),
                configuration.getCrawlSpecificationReader().getWaitAfterEvent(),
                configuration.getCrawlSpecificationReader().getWaitAfterReloadUrl());
        break;
    }

    WebDriverBackedEmbeddedBrowserWraper browserWrapper = new WebDriverBackedEmbeddedBrowserWraper(
            internalBrowser);
    for (CJBrowserMonitor monitor : browserMonitorList) {
        browserWrapper.addMonitor(monitor);
    }
    return browserWrapper;
}

From source file:edu.umd.cs.guitar.ripper.WebDriverTest.java

License:Open Source License

@Test
public void testDriverBehaviors() {
    System.out.println("testDriverBehaviors");
    FirefoxProfile profile = new FirefoxProfile(new File("/home/baonn/.mozilla/firefox"));
    profile.setPreference("network.http.phishy-userpass-length", 255);
    FirefoxDriver driver = new FirefoxDriver(profile);
    driver.get("https://www.google.com/analytics/web/");

}

From source file:fr.jetoile.demo.breizhcamp.webapp.driver.WebDriverFactory.java

License:Apache License

private static WebDriver firefoxDriver(DesiredCapabilities capabilities) {
    return new FirefoxDriver(capabilities);
}

From source file:GlennsPack.GlennWebAPI.Keybr.java

License:Open Source License

public Keybr() {
    //        System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    //        System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");

    ProfilesIni profileObj = new ProfilesIni();
    FirefoxProfile yourFFProfile = profileObj.getProfile("Glenn");

    WebDriver driver;/*from w w  w. j a v  a2 s  .co m*/

    driver = new FirefoxDriver(yourFFProfile);
    driver.get("https://www.keybr.com/practice");

    try {
        Thread.sleep(1000);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Scanner reader = new Scanner(System.in); // Reading from System.in
    System.out.println("Enter a number: ");
    int n = reader.nextInt();

    runer(driver);
}

From source file:ike.Ike.java

public static void main(String[] args) throws InterruptedException, FileNotFoundException, IOException {
    setProps();/*ww w. j  a  v a  2  s  . c  om*/
    FirefoxOptions options = new FirefoxOptions().setProfile(new FirefoxProfile());
    Proxy proxy = new Proxy();
    proxy.setProxyType(Proxy.ProxyType.AUTODETECT);
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("proxy", proxy);
    WebDriver driver = new FirefoxDriver(capabilities);
    driver.get("https://sise2mx.ikeasistencia.com/");
    driver.findElement(By.id("Usr")).clear();
    driver.findElement(By.id("Usr")).sendKeys("cmantenimiento");
    driver.findElement(By.id("Pass")).clear();
    driver.findElement(By.id("Pass")).sendKeys(readPass());
    driver.findElement(By.id("btnLogin")).click();
    for (int i = 0; i < 1; i = 0) {
        Thread.sleep(3100);
        if ((isElementPresent(("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button"), driver)) == true) {
            driver.findElement(By.xpath("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button")).click();
            System.out.println("Has aceptado un nuevo expediente.");
            System.out.println("Fecha: " + timeStamp());
            //msg();
        }
        if ((isElementPresent(("//*[@id=\"msg_alerta\"]/table/tbody/tr/td/table/tbody/tr[4]/td/button"),
                driver)) == true) {
            driver.findElement(
                    By.xpath("//*[@id=\"msg_alerta\"]/table/tbody/tr/td/table/tbody/tr[4]/td/button")).click();
            if ((isElementPresent(("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button"), driver)) == true) {
                driver.findElement(By.xpath("//*[@id=\"PW_LST\"]/tbody/tr[3]/td[10]/button")).click();
            }
            System.out.println("Has aceptado un nuevo expediente.");
            System.out.println("Fecha: " + timeStamp());
            //msg();
        }
        if ((isElementPresent(("//*[@id=\"MensajeTimeOut\"]/table"), driver)) == true) {
            driver.findElement(
                    By.xpath("//*[@id=\"MensajeTimeOut\"]/table/tbody/tr/td/table/tbody/tr[4]/td[2]/button"))
                    .click();
        } else {
            driver.findElement(By.xpath("//div[2]/div[2]/table/tbody/tr/td")).click();
        }
    }
}

From source file:info.magnolia.integrationtests.uitest.AbstractMagnoliaUITest.java

License:Open Source License

/**
 * Returns a new {@link WebDriver} to be used for all tests.
 *
 * If a system property {@link #SELENIUM_SERVER_HOST_NAME} was provided with a hostname a {@link RemoteWebDriver} will be
 * returned, otherwise the default {@link FirefoxDriver}.
 */// w ww  .j a va 2  s .c  o  m
protected WebDriver getNewWebDriver() {
    // Set the download dir which might be overwritten in subclasses
    firefoxProfile.setPreference("browser.download.dir", getDownloadDir());

    // Set our custom profile as desired capabilities
    capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

    // If a vmHostName was supplied then we're executing the tests in a Virtual Machine
    String vmHostName = System.getProperty(SELENIUM_SERVER_HOST_NAME);
    if (StringUtils.isNotBlank(vmHostName)) {
        try {
            URL seleniumServerUrl = new URL(String.format("http://%s:4444/wd/hub", vmHostName));
            return new RemoteWebDriver(seleniumServerUrl, capabilities);
        } catch (MalformedURLException e) {
            log.error("VM hostname was set [{}] but couldn't setup URL", vmHostName, e);
        }
    }

    return new FirefoxDriver(capabilities);
}

From source file:io.ddavison.conductor.Locomotive.java

License:Open Source License

public Locomotive() {
    final Properties props = new Properties();
    try {//from ww  w  . j  av a2 s .c o m
        props.load(getClass().getResourceAsStream("/default.properties"));
    } catch (IOException e) {
        logFatal("Couldn't load in default properties");
    } catch (Exception e) {
    }

    /**
     * Order of overrides:
     * <ol>
     *     <li>Test</li>
     *     <li>JVM Arguments</li>
     *     <li>Default properties</li>
     * </ol>
     */
    final Config testConfiguration = getClass().getAnnotation(Config.class);

    configuration = new LocomotiveConfig(testConfiguration, props);

    DesiredCapabilities capabilities;

    Capabilities extraCapabilities;
    try {
        extraCapabilities = configuration.capabilities().newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
        logFatal(e.getMessage());
        System.exit(1);
        return;
    }

    baseUrl = configuration.url();

    log.debug(String.format(
            "\n=== Configuration ===\n" + "\tURL:     %s\n" + "\tBrowser: %s\n" + "\tHub:     %s\n"
                    + "\tBase url: %s\n",
            configuration.url(), configuration.browser().moniker, configuration.hub(),
            configuration.baseUrl()));

    boolean isLocal = StringUtils.isEmpty(configuration.hub());

    switch (configuration.browser()) {
    case CHROME:
        capabilities = DesiredCapabilities.chrome();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new ChromeDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case FIREFOX:
        capabilities = DesiredCapabilities.firefox();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new FirefoxDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case INTERNET_EXPLORER:
        capabilities = DesiredCapabilities.internetExplorer();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new InternetExplorerDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case EDGE:
        capabilities = DesiredCapabilities.edge();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new EdgeDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case SAFARI:
        capabilities = DesiredCapabilities.safari();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new SafariDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    case PHANTOMJS:
        capabilities = DesiredCapabilities.phantomjs();
        capabilities.merge(extraCapabilities);
        if (isLocal)
            try {
                driver = new PhantomJSDriver(capabilities);
            } catch (Exception x) {
                x.printStackTrace();
                logFatal(
                        "Also see https://github.com/conductor-framework/conductor/wiki/WebDriver-Executables");
                System.exit(1);
            }
        break;
    default:
        System.err.println("Unknown browser: " + configuration.browser());
        return;
    }

    if (!isLocal)
        // they are using a hub.
        try {
            capabilities.merge(extraCapabilities);
            driver = new RemoteWebDriver(new URL(configuration.hub()), capabilities); // just override the driver.
        } catch (Exception x) {
            logFatal("Couldn't connect to hub: " + configuration.hub());
            x.printStackTrace();
            return;
        }

    actions = new Actions(driver);

    if (StringUtils.isNotEmpty(baseUrl))
        driver.navigate().to(baseUrl);
}

From source file:io.github.bonigarcia.wdm.test.WebRtcFirefoxTest.java

License:Apache License

@Before
public void setupTest() {
    FirefoxOptions options = new FirefoxOptions();

    // This flag avoids granting the access to the camera
    options.addPreference("media.navigator.permission.disabled", true);

    // This flag force to use fake user media (synthetic video of multiple
    // color)//ww  w.  ja  v a 2 s .co  m
    options.addPreference("media.navigator.streams.fake", true);

    driver = new FirefoxDriver(options);
}

From source file:io.github.seleniumquery.browser.driver.builders.FirefoxDriverBuilder.java

License:Apache License

private WebDriver buildFirefox() {
    return new FirefoxDriver(getInitializedFirefoxOptions());
}

From source file:io.openvidu.test.browsers.FirefoxUser.java

License:Apache License

public FirefoxUser(String userName, int timeOfWaitInSeconds) {
    super(userName, timeOfWaitInSeconds);

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setAcceptInsecureCerts(true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
    FirefoxProfile profile = new FirefoxProfile();

    // This flag avoids granting the access to the camera
    profile.setPreference("media.navigator.permission.disabled", true);
    // This flag force to use fake user media (synthetic video of multiple color)
    profile.setPreference("media.navigator.streams.fake", true);

    capabilities.setCapability(FirefoxDriver.PROFILE, profile);

    String REMOTE_URL = System.getProperty("REMOTE_URL_FIREFOX");
    if (REMOTE_URL != null) {
        log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
        try {/*from   w w w  . j a  v a2 s  .com*/
            this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else {
        log.info("Using local web driver");
        this.driver = new FirefoxDriver(capabilities);
    }

    this.configureDriver();
}