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() 

Source Link

Usage

From source file:com.pineapple.eckotur.web.test.RegisterTest.java

@BeforeClass
public static void setUp() throws Exception {
    driver = new FirefoxDriver();
    // se define el url base del proyecto web
    baseUrl = "http://localhost:8080/Eckotur.service/login.html";
    /* Indica cuanto se espera para la respuesta de cualquier comando realizado hacia el navegador*/
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.pivotal.gemfire.tools.pulse.tests.PulseTests.java

License:Open Source License

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    try {/*from w ww  .  j  av  a2s.  c  o  m*/
        server = Server.createServer(9999, jmxPropertiesFile);

        String host = "localhost";// InetAddress.getLocalHost().getHostAddress();
        int port = 8080;
        String context = "/pulse";

        tomcat = TomcatHelper.startTomcat(host, port, context, path);
        pulseURL = "http://" + host + ":" + port + context;

        Thread.sleep(5000); // wait till tomcat settles down
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        Assert.fail("Error " + e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail("Error " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Error " + e.getMessage());
    }

    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get(pulseURL);
    WebElement userNameElement = driver.findElement(By.id("user_name"));
    WebElement passwordElement = driver.findElement(By.id("user_password"));
    userNameElement.sendKeys(userName);
    passwordElement.sendKeys(pasword);
    passwordElement.submit();

    Thread.sleep(10000);
    WebElement userNameOnPulsePage = (new WebDriverWait(driver, 10)).until(new ExpectedCondition<WebElement>() {
        @Override
        public WebElement apply(WebDriver d) {
            return d.findElement(By.id("userName"));
        }
    });
    Assert.assertNotNull(userNameOnPulsePage);
    Thread.sleep(7000);
}

From source file:com.qaprosoft.carina.core.demo.NativeSeleniumTest.java

License:Apache License

@BeforeTest
public void init() {
    driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.rakhi.selenium.endtoend.EndToEndTest.java

@Before
public void setUp() throws Exception {
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    baseUrl = "https://www.google.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

From source file:com.rakhi.selenium.readfromexcel.ReadDataFromExcelFileTest.java

@Before
public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl1 = "https://osc.npu.edu/Account/Logon?enc=td2nmreLJyypG4lX9oxb4obTqnVB8pwMcILEgDP1ajfK4QYWfetEDr2JalCyz0fB";
    baseUrl2 = "http://google.com/";
}

From source file:com.rakhi.selenium.registeraccount.NpuRegisterAccountTest.java

@Before
public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl1 = "http://npu.edu/";
    baseUrl2 = "http://google.com/";
}

From source file:com.smash.revolance.ui.model.bot.BrowserFactory.java

License:Open Source License

public static void instanceciateNavigator(User user, BrowserType browserType) throws InstanciationError {
    final Logger logger = user.getLogger();

    if (!user.isExplorationDone()) {
        WebDriver browser = null;/*ww  w.  j  av  a  2 s.  c  om*/
        DriverService service = null;

        if (browserType == BrowserType.Firefox) {
            browser = new FirefoxDriver();
        } else if (browserType == BrowserType.Chrome) {
            File driver = new File(user.getDriverPath());
            File binary = new File(user.getBrowserPath());

            // ImmutableMap<String, String> env = new ImmutableMap.Builder<String, String>().build();
            ChromeDriverService.Builder serviceBuilder = new ChromeDriverService.Builder()
                    .usingDriverExecutable(driver).usingAnyFreePort();

            // serviceBuilder.withEnvironment( env );
            service = serviceBuilder.build();
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            capabilities.setCapability("chrome.binary", binary.getAbsolutePath());
            // capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));

            browser = new ChromeDriver((ChromeDriverService) service, capabilities);
        } else if (browserType == BrowserType.PhantomJS) {
            DesiredCapabilities cfg = DesiredCapabilities.phantomjs();
            cfg.setJavascriptEnabled(true);

            try {
                service = ResolvingPhantomJSDriverService.createDefaultService(cfg);

                // service resolving phantomjs binary automatically
                browser = new PhantomJSDriver(service, cfg);
            } catch (IOException e) {
                throw new InstanciationError("Unable to start ghost web driver!", e);
            }
        } else if (browserType == BrowserType.MockedWebDriver) {
            try {
                System.setProperty("webdriver.remote.server", String.valueOf(9090));
                browser = new MockedWebDriver(9090);
            } catch (MalformedURLException e) {
                throw new InstanciationError("Unable to start the mocked web driver!", e);
            }
        }

        if (browser != null) {
            browser.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            logger.log(Level.INFO, "Launching a " + browser + " browser");

            browser.manage().window().setSize(new Dimension(user.getBrowserWidth(), user.getBrowserHeight()));
            logger.log(Level.INFO,
                    "Setting up resolution to: " + user.getBrowserWidth() + "x" + user.getBrowserHeight());

            user.setBrowser(browser);
            user.setBrowserActive(true);
        } else {
            logger.log(Level.ERROR, "Unable to start the browser: " + browser);
        }

        if (service != null) {
            user.setDriverService(service);
        }
    }
}

From source file:com.sol.browser.DriverFactory.java

License:Apache License

/**
 * Returns an instance of the requested WebDriver.
 * This method also sets the implicite waiting time according to the
 * property in the property file.//from w  ww  .  ja  v a 2  s  .com
 * @param driverType - name of the requested driver
 * @return if the requested driver is valid, returns an instant of the
 * requested driver. If the requested driver is invalid, null is returned.
 * @throws FileNotFoundException if property file is not found
 * @throws IOException
 * @throws NullPointerException if {@code browser} is {@code null}
 * @throws IllegalArgumentException if the driver type is not one of the
 * following: Chrome, Firefox, or HTMLUnit.
 * <br><b>Note:</b> The following keys <em>must</em> be present in the
 * properties file (and containing values): the <em>absolute</em> path
 * to the requested WebDriver (in case of ChromeDriver), and the default
 * waiting time for the implicit wait. Missing keys may cause undefined
 * behavior.
 * @see BrowserPropertyFile
 */
public static WebDriver getDriver(final DriverType driverType)
        throws FileNotFoundException, IOException, NullPointerException, IllegalArgumentException {

    Objects.requireNonNull(driverType);
    WebDriver driver = null;
    BrowserPropertyFile properties = BrowserPropertyFile.getInstance();

    switch (driverType) {
    case CHROME:
        String pathToDriver = properties.getProperty(BrowserPropertyConstants.PATH_TO_DRIVER);
        System.setProperty("webdriver.chrome.driver", pathToDriver);
        driver = new ChromeDriver();
        break;
    case FIREFOX:
        driver = new FirefoxDriver();
        break;
    case HTMLUNIT:
        driver = new HtmlUnitDriver();
        break;
    default:
        throw new IllegalArgumentException("Illegal driver type");
    }

    String waitingTime = properties.getProperty(BrowserPropertyConstants.IMPLICITE_WAITING_TIME);
    long implicitWaitingTime = Long.parseLong(waitingTime);

    driver.manage().timeouts().implicitlyWait(implicitWaitingTime, TimeUnit.SECONDS);

    return driver;
}

From source file:com.spambot.invisicow.SeleniumDriver.java

public void drive(int opt) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("http://findtheinvisiblecow.com");

    WebElement body = driver.findElement(By.tagName("body"));
    new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(body));

    //start game     
    WebElement button = driver.findElement(By.xpath("//div[@id='loader']//button"));
    new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(button));
    button.click();//from  www . jav  a  2 s .  c  o  m

    for (int i = 0; i < opt - 1; i++) {
        //so the user sees something
        Thread.sleep(2500);

        //win game
        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript("find.gameStop(true);");
        }

        //again?
        WebElement congrats = driver.findElement(By.id("modal-congratulations"));
        new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(congrats));
        Thread.sleep(1500);
        WebElement again = driver.findElement(By.xpath("//div[@id='modal-congratulations']//button"));
        again.click();
    }

    Thread.sleep(2500);
    //win game one last time
    if (driver instanceof JavascriptExecutor) {
        ((JavascriptExecutor) driver).executeScript("find.gameStop(true);");
    }

    Thread.sleep(3000);

    JOptionPane.showMessageDialog(null, "Goodbye!");

    driver.quit();
}

From source file:com.spambot.invisicow.SeleniumDriver.java

public void driveExample() {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();//w  ww  . j  a v a  2s  .c o m

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}