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

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

Introduction

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

Prototype

@Override
    public String getWindowHandle() 

Source Link

Usage

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

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();// w  ww . j a  va 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.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 {//w w  w. ja va2s  .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();
        }
    }
}