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

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

Introduction

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

Prototype

@Override
    public String getPageSource() 

Source Link

Usage

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

@Test
public void testTestBenchDriverActsAsProxy() {
    FirefoxDriver mockDriver = createMock(FirefoxDriver.class);
    mockDriver.close();//from  ww  w . j  ava 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:NCB.Extractor.java

public static void idextractor(FirefoxDriver driver) {
    try {// w ww.  j ava  2 s  .  c o  m
        String src = null;
        db = new DBActivityMInsLM();
        stUpdte = db.con.createStatement();

        ResultSet count = stUpdte.executeQuery("select * from NCB_Linkids where status=0");

        while (count.next()) {
            strInputid = count.getString("Link");

            System.out.println(strInputid);
            driver.navigate().to(strInputid);
            Thread.sleep(2000);
            src = driver.getPageSource().toString();
            Thread.sleep(3000);
            extractData(src, strInputid);
            String q = "update NCB_Linkids set Status=1 where Link='" + strInputid + "'";
            System.out.println(q);
            stUpdte = db.con.createStatement();
            stUpdte.executeUpdate(q);
            stUpdte.close();

        }
        stmtdelete.executeUpdate("Truncate NCB_Linkids");
        stmtdelete.close();
        db.closeDB();
        driver.close();

    } catch (Exception e) {
        System.out.println("Error in idextraction" + e);
    }

}

From source file:plugins.KerberosSsoTest.java

License:Open Source License

private void verifyTicketAuth(KerberosContainer kdc) throws IOException, InterruptedException {
    // Get TGT/*from  www. j  a  v a 2s. c  o m*/
    String tokenCache = kdc.getClientTokenCache();

    // Correctly negotiate in browser
    FirefoxDriver negotiatingDriver = getNegotiatingFirefox(kdc, tokenCache);
    negotiatingDriver.get(jenkins.url("/whoAmI").toExternalForm());
    String out = negotiatingDriver.getPageSource();
    assertThat(out, containsString(AUTHORIZED));

    // Non-negotiating request should fail
    assertUnauthenticatedRequestIsRejected(getBadassHttpClient());
}

From source file:plugins.KerberosSsoTest.java

License:Open Source License

@Test
public void explicitTicketAuth() throws Exception {
    setupRealmUser();// w  ww .j a v a  2  s.  c  o m
    KerberosContainer kdc = startKdc();
    configureSso(kdc, true, true);

    String tokenCache = kdc.getClientTokenCache();

    FirefoxDriver nego = getNegotiatingFirefox(kdc, tokenCache);
    nego.get(jenkins.url("/whoAmI").toExternalForm());
    assertThat(nego.getPageSource(), not(containsString(AUTHORIZED)));

    nego.get(jenkins.url("/login").toExternalForm());
    nego.get(jenkins.url("/whoAmI").toExternalForm());
    assertThat(nego.getPageSource(), containsString(AUTHORIZED));
}

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  w  w. j a  v  a2  s. 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  www .j  a v  a2s.  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  w w . ja  v a2s  .com*/
        // 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.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 {/*from   ww w. j  a v  a 2s. 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();
        }
    }
}