Example usage for org.openqa.selenium WebDriver get

List of usage examples for org.openqa.selenium WebDriver get

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver get.

Prototype

void get(String url);

Source Link

Document

Load a new web page in the current browser window.

Usage

From source file:com.galenframework.tests.api.GalenTest.java

License:Apache License

@Test
public void dumpPage_shouldGenereate_htmlJsonReport_andStorePicturesOfElements() throws IOException {
    String pageDumpPath = Files.createTempDir().getAbsolutePath() + "/pagedump";

    WebDriver driver = new MockedDriver();
    driver.get("/mocks/pages/galen4j-pagedump.json");
    Galen.dumpPage(driver, "test page", "/specs/galen4j/pagedump.spec", pageDumpPath);

    assertFileExists(pageDumpPath + "/page.json");
    assertJSONContent(pageDumpPath + "/page.json", "/pagedump/expected.json");
    assertFileExists(pageDumpPath + "/page.html");

    assertFileExists(pageDumpPath + "/page.png");
    assertFileExists(pageDumpPath + "/objects/button-save.png");
    assertFileExists(pageDumpPath + "/objects/name-textfield.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-1.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-2.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-3.png");
    assertFileExists(pageDumpPath + "/objects/big-container.png");

    assertFileExists(pageDumpPath + "/jquery-1.11.2.min.js");
    assertFileExists(pageDumpPath + "/galen-pagedump.js");
    assertFileExists(pageDumpPath + "/galen-pagedump.css");
}

From source file:com.galenframework.tests.api.GalenTest.java

License:Apache License

@Test
public void dumpPage_shouldOnlyStoreScreenshots_thatAreLessThan_theMaxAllowed() throws IOException {
    String pageDumpPath = Files.createTempDir().getAbsolutePath() + "/pagedump";

    WebDriver driver = new MockedDriver();
    driver.get("/mocks/pages/galen4j-pagedump.json");
    Galen.dumpPage(driver, "test page", "/specs/galen4j/pagedump.spec", pageDumpPath, 80, 80, false);

    assertFileExists(pageDumpPath + "/objects/button-save.png");
    assertFileDoesNotExist(pageDumpPath + "/objects/name-textfield.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-1.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-2.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-3.png");
    assertFileDoesNotExist(pageDumpPath + "/objects/big-container.png");

    assertFileExists(pageDumpPath + "/page.json");
    assertFileExists(pageDumpPath + "/page.html");
    assertFileExists(pageDumpPath + "/jquery-1.11.2.min.js");
    assertFileExists(pageDumpPath + "/galen-pagedump.js");
    assertFileExists(pageDumpPath + "/galen-pagedump.css");
}

From source file:com.galenframework.tests.api.GalenTest.java

License:Apache License

@Test
public void dumpPage_shouldOnlyStoreScreenshots_withoutHtmlReport() throws IOException {
    String pageDumpPath = Files.createTempDir().getAbsolutePath() + "/pagedump";

    WebDriver driver = new MockedDriver();
    driver.get("/mocks/pages/galen4j-pagedump.json");
    Galen.dumpPage(driver, "test page", "/specs/galen4j/pagedump.spec", pageDumpPath, 80, 80, true);

    assertFileExists(pageDumpPath + "/objects/button-save.png");
    assertFileDoesNotExist(pageDumpPath + "/objects/name-textfield.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-1.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-2.png");
    assertFileExists(pageDumpPath + "/objects/menu-item-3.png");
    assertFileDoesNotExist(pageDumpPath + "/objects/big-container.png");

    assertFileDoesNotExist(pageDumpPath + "/page.json");
    assertFileDoesNotExist(pageDumpPath + "/page.html");
    assertFileDoesNotExist(pageDumpPath + "/jquery-1.11.2.min.js");
    assertFileDoesNotExist(pageDumpPath + "/galen-pagedump.js");
    assertFileDoesNotExist(pageDumpPath + "/galen-pagedump.css");
}

From source file:com.gargoylesoftware.htmlunit.CookieManager4Test.java

License:Apache License

/**
 * Clear browser cookies.//  w  w  w .  ja  v  a2s . c  o m
 *
 * @throws Exception if the test fails
 */
@Before
public void clearCookies() throws Exception {
    getMockWebConnection().setDefaultResponse("<html><head></head><body></body></html>");
    startWebServer(getMockWebConnection());
    final WebDriver driver = getWebDriver();
    driver.get(URL_HOST1);
    driver.manage().deleteAllCookies();
    driver.get(URL_HOST2);
    driver.manage().deleteAllCookies();
    driver.get(URL_HOST3);
    driver.manage().deleteAllCookies();
    driver.get(URL_HOST4);
    driver.manage().deleteAllCookies();
    stopWebServers();
}

From source file:com.gargoylesoftware.htmlunit.CookieManagerTest.java

License:Apache License

/**
 * Regression test for issue 2973040.//from w  ww  .  j  a v a2 s  .c  o  m
 * When a cookie is set with value within quotes, this value should be sent within quotes
 * in the following requests. This is a problem (bug?) in HttpClient which is not fixed in HttpClient-4.0.1.
 * @see <a href="https://issues.apache.org/jira/browse/HTTPCLIENT-1006">HttpClient bug 1006</a>
 * @throws Exception if the test fails
 */
@Test
public void valueQuoted() throws Exception {
    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "key=value"));
    responseHeader.add(new NameValuePair("Set-Cookie", "test=\"aa= xx==\""));
    getMockWebConnection().setResponse(URL_FIRST, "", 200, "OK", "text/html", responseHeader);
    getMockWebConnection().setDefaultResponse("");

    final WebDriver driver = loadPageWithAlerts2(URL_FIRST);

    driver.get(URL_SECOND.toExternalForm());

    // strange check, but there is no order
    final String lastCookies = getMockWebConnection().getLastAdditionalHeaders().get("Cookie");
    assertEquals(26, lastCookies.length());
    assertTrue("lastCookies: " + lastCookies, lastCookies.contains("key=value")
            && lastCookies.contains("test=\"aa= xx==\"") && lastCookies.contains("; "));
}

From source file:com.gargoylesoftware.htmlunit.CookieManagerTest.java

License:Apache License

private void ensureCookieValueIsSentBackUnquoted(final String cookie) throws Exception {
    final List<NameValuePair> responseHeaders = new ArrayList<>();
    responseHeaders.add(new NameValuePair("Set-Cookie", cookie + "; Path=/; Version=1"));
    getMockWebConnection().setResponse(URL_FIRST, "", 200, "OK", "text/html", responseHeaders);
    getMockWebConnection().setDefaultResponse("");

    final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
    driver.get(URL_SECOND.toExternalForm());

    final String lastCookie = getMockWebConnection().getLastAdditionalHeaders().get("Cookie");
    assertEquals(cookie, lastCookie);/* ww w .j  a v  a 2s .  c om*/
}

From source file:com.gargoylesoftware.htmlunit.CookieManagerTest.java

License:Apache License

/**
 * HttpOnly cookies should not be available from JS.
 * @throws Exception if the test fails// ww w.j  ava  2 s  . c  om
 */
@Test
@Alerts("second=2")
public void httpOnly() throws Exception {
    final List<NameValuePair> responseHeader = new ArrayList<>();
    responseHeader.add(new NameValuePair("Set-Cookie", "first=1; path=/; HttpOnly"));
    responseHeader.add(new NameValuePair("Set-Cookie", "second=2; path=/;"));

    getMockWebConnection().setDefaultResponse("");
    getMockWebConnection().setResponse(URL_FIRST, HTML_ALERT_COOKIE, 200, "OK", "text/html", responseHeader);

    final WebDriver driver = loadPageWithAlerts2(URL_FIRST);
    driver.get(URL_FIRST + "foo");

    final Map<String, String> lastHeaders = getMockWebConnection().getLastAdditionalHeaders();

    // strange check, but there is no order
    final String lastCookies = lastHeaders.get("Cookie");
    assertEquals(17, lastCookies.length());
    assertTrue("lastCookies: " + lastCookies,
            lastCookies.contains("first=1") && lastCookies.contains("second=2") && lastCookies.contains("; "));

    if (driver instanceof HtmlUnitDriver) {
        final CookieManager mgr = getWebWindowOf((HtmlUnitDriver) driver).getWebClient().getCookieManager();
        assertEquals(2, mgr.getCookies().size());
        assertTrue(mgr.getCookie("first").isHttpOnly());
        assertFalse(mgr.getCookie("second").isHttpOnly());
    }
}

From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProvider2Test.java

License:Apache License

/**
 * @throws Exception if an error occurs//from w w  w.ja  v  a 2  s  .  co  m
 */
@Test
public void basicAuthenticationTwice() throws Exception {
    ((DefaultCredentialsProvider) getWebClient().getCredentialsProvider()).addCredentials("jetty", "jetty");

    getMockWebConnection().setResponse(URL_SECOND, "Hello World");
    final WebDriver driver = loadPage2("Hi There");
    assertTrue(driver.getPageSource().contains("Hi There"));
    driver.get(URL_SECOND.toExternalForm());
    assertTrue(driver.getPageSource().contains("Hello World"));
}

From source file:com.gargoylesoftware.htmlunit.HistoryTest.java

License:Apache License

/**
 * Tests going in history {@link History#back()} with {@code POST} request.
 *
 * @throws Exception if an error occurs//from  w w  w. j  a va 2s  .c  om
 */
@Test
public void post() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    servlets.put("/post1", Post1Servlet.class);
    servlets.put("/post2", Post2Servlet.class);
    servlets.put("/post3", Post3Servlet.class);
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();
    driver.get(URL_FIRST + "post1");

    driver.findElement(By.id("mySubmit")).click();
    assertEquals(URL_FIRST + "post2", driver.getCurrentUrl());
    assertTrue(driver.getPageSource().contains("POST"));
    assertTrue(driver.getPageSource().contains("para1=value1"));

    driver.findElement(By.linkText("Go to GET")).click();
    assertEquals(URL_FIRST + "post3", driver.getCurrentUrl());
    assertTrue(driver.getPageSource().contains("GET"));

    driver.navigate().back();
    assertEquals(URL_FIRST + "post2", driver.getCurrentUrl());
    assertTrue(driver.getPageSource().contains("POST"));
    assertTrue(driver.getPageSource().contains("para1=value1"));
}

From source file:com.gargoylesoftware.htmlunit.HistoryTest.java

License:Apache License

/**
 * Tests going in history {@link History#back()} with {@code POST} request.
 *
 * @throws Exception if an error occurs//w  w w  .  j a va2  s .co m
 */
@Test
@Alerts("49")
// limit varies for IE
public void historyCache() throws Exception {
    final Map<String, Class<? extends Servlet>> servlets = new HashMap<>();
    final int testDeep = 70;

    for (int i = 0; i < testDeep; i++) {
        servlets.put("/post" + i, Post1Servlet.class);
    }
    startWebServer("./", new String[0], servlets);

    final WebDriver driver = getWebDriver();

    int count = Post1Servlet.Count_;
    for (int i = 0; i < testDeep; i++) {
        driver.get(URL_FIRST + "post" + i);
        assertTrue(driver.getPageSource(), driver.getPageSource().contains("Call: " + (i + count)));
    }

    count = Post1Servlet.Count_;
    for (int i = 0; i < testDeep - 1; i++) {
        driver.navigate().back();
        if (!driver.getPageSource().contains("Call: " + (count - i - 2))) {
            assertEquals(Integer.parseInt(getExpectedAlerts()[0]), i);
            return;
        }

        if (count != Post1Servlet.Count_) {
            Assert.fail("Server called for " + i);
            break;
        }
    }

    assertEquals(getExpectedAlerts()[0], "done");
}