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

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

Introduction

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

Prototype

@Override
    public String getTitle() 

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  .  ja v  a  2 s.c  o  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.ext.test.arquillian.Test01.java

License:Apache License

@Test
public void test01(@ArquillianResource final URL httpContext) throws Exception {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(new File("../opt/firefox/7x16slsr.default"));
    profile.setPreference("network.dns.disableIPv6", true);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    try {/*from w ww .  ja va  2s .c  o  m*/
        if (Test01.DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client start"));
        }
        driver.get(new URL(httpContext, TestAccordion01Page.MNT_PATH).toString());
        final String title = driver.getTitle();
        if (Test01.DEBUG.isDebug()) {
            System.out.println(timer.toString("Page title is: " + title));
            System.out.println(driver.getPageSource());
        }
        Assert.assertEquals("Test", driver.getTitle());
        final List<WebElement> p1 = driver.findElementsByLinkText("Panel1");
        final List<WebElement> p2 = driver.findElementsByLinkText("Panel2");
        final List<WebElement> p3 = driver.findElementsByLinkText("Panel3");
        final List<WebElement> c1 = driver.findElementsById("content1");
        final List<WebElement> c2 = driver.findElementsById("content2");
        final List<WebElement> c3 = driver.findElementsById("content3");
        Assert.assertEquals(1, p1.size());
        Assert.assertEquals(1, p2.size());
        Assert.assertEquals(1, p3.size());
        Assert.assertEquals(1, c1.size());
        Assert.assertEquals(1, c2.size());
        Assert.assertEquals(1, c3.size());
        Assert.assertEquals("", c2.get(0).getAttribute("style"));
        //
        p2.get(0).click();
        if (Test01.DEBUG.isDebug()) {
            System.out.println(driver.getPageSource());
        }
        final List<WebElement> cc1 = driver.findElementsById("content1");
        final List<WebElement> cc2 = driver.findElementsById("content2");
        final List<WebElement> cc3 = driver.findElementsById("content3");
        Assert.assertEquals(1, cc1.size());
        Assert.assertEquals(1, cc2.size());
        Assert.assertEquals(1, cc3.size());
        Assert.assertEquals("display: none;", cc2.get(0).getAttribute("style"));
        //
        p2.get(0).click();
        if (Test01.DEBUG.isDebug()) {
            System.out.println(driver.getPageSource());
        }
        final List<WebElement> ccc2 = driver.findElementsById("content2");
        Assert.assertEquals(1, ccc2.size());
        Assert.assertEquals("display: block;", ccc2.get(0).getAttribute("style"));
    } finally {
        if (Test01.DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            FileUtil.writeFile(Test01.test01Html, false, text);
            SeleniumTestUtil.takeScreenshot(driver, Test01.test01Png);
            System.out.println(timer.toString("# Client done"));
        }
        if (Test01.DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}

From source file:sf.wicklet.gwt.client.test.Test01.java

License:Apache License

@Test
public void testHome01() throws IOException {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(firefoxProfileDir);
    profile.setPreference("network.dns.disableIPv6", true);
    // final FirefoxDriver driver = new FirefoxDriver(new FirefoxBinary(firefoxBinary), profile);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    try {//from ww  w  .j  a va 2 s.  c  o  m
        if (DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client start"));
        }
        driver.get(BASEURL);
        final String title = driver.getTitle();
        if (DEBUG.isDebug()) {
            System.out.println(timer.toString("Page title is: " + title));
        }
        assertEquals("HomePage", title);
        if (DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            System.out.println(text);
            FileUtil.writeFile(testHome01Html, false, text);
            takeScreenshot(driver, testHome01Png);
        }
        toppanel(driver);
        logindialog(driver);
        menubar(driver);
        stackpanel(driver);
        ajaxpanel(driver);
    } catch (final Throwable e) {
        e.printStackTrace();
        throw e;
    } finally {
        if (DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client done"));
        }
        if (DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}

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 {//  w ww  .  j  av a 2s. 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();
        }
    }
}

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

License:Apache License

@Test
public void testWiki01() throws 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 {//from   w  w  w .j a  va 2s.c om
        debugprint(timer, "# Client start");
        driver.get(BASEURL);
        final String title = driver.getTitle();
        debugprint(timer, "# Page title is: " + title);
        assertEquals("Wicklet", title);
        findAndClick(driver.findElementById("leftTopPanel"), By.linkText("Projects"));
        // No edit link without login
        findAndCount(driver.findElementById("rightPanel"), By.linkText("Edit"), 0);
        // login
        findAndClick(driver, By.linkText("Login"));
        login(driver, "writer", "writer");
        //
        findAndClick(driver.findElementById("rightPanel"), By.linkText("Edit"));
        waitAndCount(driver, By.cssSelector(".gwt-RichTextToolbar"), 1);
        findAndCount(driver, By.cssSelector("iframe.gwt-RichTextArea"), 1);
        takeSnapshot(driver, htmlfile("TestWiki01"), pngfile("TestWiki01"));
        final String top = driver.getWindowHandle();
        driver.switchTo().frame("richtextarea");
        waitAndCount(driver, By.tagName("h1"), 1);
        driver.switchTo().window(top);
        findAndClick(driver, By.linkText("Projects"));
        waitAndClick(driver.findElementById("rightPanel"), By.linkText("Edit"));
        waitAndCount(driver, By.cssSelector("iframe.gwt-RichTextArea"), 1);
        driver.switchTo().frame("richtextarea");
        final List<WebElement> h3s = waitAndCount(driver, By.tagName("h3"), 7);
        takeSnapshot(driver, htmlfile("TestWiki01RichTextArea"), pngfile("TestWiki01RichTextArea"));
        final String text = h3s.get(4).getText();
        assertEquals("WickletGwtServer", text);
    } finally {
        debugprint(timer, "# Client done");
        if (DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}

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

License:Apache License

private void test() throws IOException {
    final StepWatch timer = new StepWatch(true);
    final FirefoxProfile profile = new FirefoxProfile(new File("../opt/firefox/7x16slsr.default"));
    profile.setPreference("network.dns.disableIPv6", true);
    final FirefoxDriver driver = new FirefoxDriver(profile);
    try {/* w  ww. j av  a  2  s  .  c  om*/
        if (TestRestart01.DEBUG.isDebug()) {
            System.out.println(timer.toString("# Client start"));
        }
        driver.get("http://localhost:8080/wicklet-site/");
        final String title = driver.getTitle();
        if (TestRestart01.DEBUG.isDebug()) {
            System.out.println(timer.toString("Page title is: " + title));
        }
        Assert.assertEquals("Wicklet", driver.getTitle());
    } finally {
        if (TestRestart01.DEBUG.isDebug()) {
            final String text = driver.getPageSource();
            System.out.println(text);
            FileUtil.writeFile(TestRestart01.testHome01Html, false, text);
            takeScreenshot(driver, TestRestart01.testHome01Png);
            System.out.println(timer.toString("# Client done"));
        }
        if (TestRestart01.DEBUG.isDebugServer()) {
            System.in.read();
        } else {
            driver.quit();
        }
    }
}

From source file:sf.wicklet.test.support.SeleniumTestUtil.java

License:Apache License

public static void debugprint(final FirefoxDriver driver, final boolean debug, final StepWatch timer,
        final String url, final Response response) {
    if (debug) {/*from w w  w  .  j  av a  2  s.c o  m*/
        System.out.println("###");
        System.out.println("### " + url);
        System.out.println("###");
        System.out.println(timer.toString("Page title is: " + driver.getTitle()));
        System.out.println(response.getValue());
        System.out.println("# sessionId: " + response.getSessionId());
        System.out.println("# status: " + response.getStatus());
    }
}