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

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

Introduction

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

Prototype

@Override
    public String getCurrentUrl() 

Source Link

Usage

From source file:com.vaadin.testbench.TestBenchDriverTest.java

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();/* w  w  w.  j  a  v a 2s .co  m*/
    expectLastCall().once();
    WebElement mockElement = createNiceMock(WebElement.class);
    expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement);
    List<WebElement> elements = Arrays.asList(mockElement);
    expect(mockDriver.findElements(isA(By.class))).andReturn(elements);
    mockDriver.get("foo");
    expectLastCall().once();
    expect(mockDriver.getCurrentUrl()).andReturn("foo");
    expect(mockDriver.getPageSource()).andReturn("<html></html>");
    expect(mockDriver.getTitle()).andReturn("bar");
    expect(mockDriver.getWindowHandle()).andReturn("baz");
    Set<String> handles = new HashSet<String>();
    expect(mockDriver.getWindowHandles()).andReturn(handles);
    Options mockOptions = createNiceMock(Options.class);
    expect(mockDriver.manage()).andReturn(mockOptions);
    Navigation mockNavigation = createNiceMock(Navigation.class);
    expect(mockDriver.navigate()).andReturn(mockNavigation);
    mockDriver.quit();
    expectLastCall().once();
    expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true);
    TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class);
    expect(mockDriver.switchTo()).andReturn(mockTargetLocator);
    replay(mockDriver);

    // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver);
    WebDriver driver = TestBench.createDriver(mockDriver);
    driver.close();
    By mockBy = createNiceMock(By.class);
    assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands);
    assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands);
    driver.get("foo");
    assertEquals("foo", driver.getCurrentUrl());
    assertEquals("<html></html>", driver.getPageSource());
    assertEquals("bar", driver.getTitle());
    assertEquals("baz", driver.getWindowHandle());
    assertEquals(handles, driver.getWindowHandles());
    assertEquals(mockOptions, driver.manage());
    assertEquals(mockNavigation, driver.navigate());
    driver.quit();
    assertEquals(mockTargetLocator, driver.switchTo());

    verify(mockDriver);
}

From source file:sf.wicklet.gwt.site.test.firefox.TestEditUser01.java

License:Apache License

@Test
public void testEditUser01() throws LifecycleException, IOException {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(firefoxProfileDir);
    profile.setPreference("network.dns.disableIPv6", true);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    // driver.manage().timeouts().implicitlyWait(1000, TimeUnit.MILLISECONDS);
    try {//  ww w . j  a  va 2  s  .  c o m
        // Check that acess to admin page redirect to https connection.
        debugprint(timer, "# Client start");
        driver.get(BASEURL + "p/admin");
        debugprint(timer.toString("# Client start"));
        assertEquals("Login", driver.getTitle());
        login(driver, USER_ADMIN, PASS_ADMIN);
        assertEquals("Admin", driver.getTitle());
        final String url = driver.getCurrentUrl();
        debugprint("# URL=" + url);
        assertTrue(url.startsWith("https"));
        // Test edit roles
        finder(driver).wait(By.cssSelector("table.zebraTable"), 1) //
                .finder(0).find(By.linkText("edit"), 4).click(0);
        final WebElement dialog = finder(driver).find(By.cssSelector(".gwt-DialogBox"), 1).get(0);
        finder(dialog).find(By.name("username"), 1);
        final WebElement roleselm = finder(dialog).find(By.name("roles"), 1).get(0);
        final String roles = roleselm.getAttribute("value");
        debugprint("# unedited roles=" + roles);
        assertFalse(roles, roles.indexOf("editor") >= 0);
        enterText(roleselm, roles + ",editor");
        finder(dialog).find(By.tagName("button"), 2).filterText("^OK$").click(0);
        TestUtil.assertWithinTimeout(new IPredicate() {
            @SuppressWarnings("synthetic-access")
            @Override
            public boolean ok() {
                final String editedroles = finder(driver)
                        .wait(By.cssSelector("table.zebraTable tr:first-child+tr td"), 3).get(1).getText();
                debugprint("# edited roles: " + editedroles);
                return editedroles.indexOf("editor") >= 0;
            }
        });
        // Test the delete link
        finder(driver).find(By.cssSelector("table.zebraTable tr")).count(5) //
                .find(By.cssSelector("table.zebraTable"), 1) //
                .finder(0).find(By.linkText("delete"), 4).click(3);
        finder(driver).wait(By.cssSelector(".gwt-DialogBox"), 1) //
                .finder(0).find(By.tagName("button"), 2).filterText("^OK$").click(0);
        finder(driver).wait(By.cssSelector("table.zebraTable tr"), 4);
    } finally {
        if (DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            System.out.println(text);
            FileUtil.writeFile(htmlfile("TestEditUser01"), false, text);
            System.out.println(timer.toString("# Client done"));
        }
        if (DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}