Example usage for org.openqa.selenium WebDriver getCurrentUrl

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

Introduction

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

Prototype

String getCurrentUrl();

Source Link

Document

Get a string representing the current URL that the browser is looking at.

Usage

From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchorTest.java

License:Apache License

/**
 * @throws Exception if the test fails//ww w .  java2  s . c  o  m
 */
@Test
@Alerts(DEFAULT = { "URLbug.html?h%F6=G%FCnter", "h\ufffd", "G\ufffdnter" }, IE = {
        "URLbug.html?h\u00F6=G\u00FCnter", "h\ufffd", "G\ufffdnter" })
public void encoding() throws Exception {
    final String html = "<html>\n" + "<head>\n"
            + "  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + "</head>\n"
            + "<body>\n" + "  <a href='bug.html?h\u00F6=G\u00FCnter' id='myLink'>Click me</a>\n"
            + "</body></html>";

    getMockWebConnection().setDefaultResponse(html, "text/html", UTF_8);

    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html, URL_FIRST);
    driver.findElement(By.id("myLink")).click();

    assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());

    final List<NameValuePair> requestedParams = getMockWebConnection().getLastWebRequest()
            .getRequestParameters();
    assertEquals(1, requestedParams.size());
    assertEquals(getExpectedAlerts()[1], requestedParams.get(0).getName());
    assertEquals(getExpectedAlerts()[2], requestedParams.get(0).getValue());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlForm2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from  ww  w.  ja v a2  s  .c o m
 */
@Test
public void linkUrlEncoding() throws Exception {
    final String html = "<html>\n" + "<head><title>foo</title>\n"
            + "  <meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>\n" + "</head>\n"
            + "<body>\n" + "  <a href='bug.html?k\u00F6nig' id='myLink'>Click me</a>\n" + "</body></html>";

    final MockWebConnection webConnection = getMockWebConnection();
    webConnection.setDefaultResponse(html, "text/html", ISO_8859_1);

    final WebDriver driver = loadPage2(html);
    assertEquals(URL_FIRST.toExternalForm(), driver.getCurrentUrl());
    driver.findElement(By.id("myLink")).click();
    final String linkSuffix;
    if (getBrowserVersion().isIE()) {
        linkSuffix = "bug.html?k\u00F6nig";
    } else {
        linkSuffix = "bug.html?k%F6nig";
    }
    assertEquals(URL_FIRST.toExternalForm() + linkSuffix, driver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlForm2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/* www .j av  a  2s.co  m*/
 */
@Test
@Alerts({ "URL?par%F6m=Hello+G%FCnter", "par\ufffdm", "Hello G\ufffdnter" })
public void encodingSubmit() throws Exception {
    final String html = "<html>\n" + "<head>\n"
            + "  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n" + "</head>\n"
            + "<body>\n" + "  <form>\n" + "    <input name='par\u00F6m' value='Hello G\u00FCnter'>\n"
            + "    <input id='mySubmit' type='submit' value='Submit'>\n" + "  </form>\n" + "</body></html>";

    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(html, URL_FIRST);
    driver.findElement(new ById("mySubmit")).click();

    assertEquals(getExpectedAlerts()[0], driver.getCurrentUrl());

    final List<NameValuePair> requestedParams = getMockWebConnection().getLastWebRequest()
            .getRequestParameters();
    assertEquals(1, requestedParams.size());
    assertEquals(getExpectedAlerts()[1], requestedParams.get(0).getName());
    assertEquals(getExpectedAlerts()[2], requestedParams.get(0).getValue());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlImageInput2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   w  w w  . j  av  a 2s  .  c  om*/
 */
@Test
@Alerts(DEFAULT = "URL?button.x=0&button.y=0", CHROME = "URL?button.x=9&button.y=7&button=foo", IE = "URL?button.x=14&button.y=15")
@NotYetImplemented({ CHROME, IE })
public void click_NoPosition() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "<input type='image' name='aButton' value='foo'/>\n"
            + "<input type='image' name='button' value='foo'/>\n"
            + "<input type='image' name='anotherButton' value='foo'/>\n" + "</form></body></html>";
    final WebDriver webDriver = loadPage2(html);
    webDriver.findElement(By.name("button")).click();

    expandExpectedAlertsVariables(URL_FIRST);
    assertEquals(getExpectedAlerts()[0], webDriver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlImageInput2Test.java

License:Apache License

/**
 * @throws Exception if the test fails// w w w.j  av  a  2s  .c  om
 */
@Test
@Alerts(DEFAULT = "URL?button.x=0&button.y=0", CHROME = "URL?button.x=22&button.y=7", IE = "URL?button.x=14&button.y=15")
@NotYetImplemented({ CHROME, IE })
public void click_NoPosition_NoValue() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "<input type='image' name='button'>\n" + "</form></body></html>";
    final WebDriver webDriver = loadPage2(html);
    webDriver.findElement(By.name("button")).click();

    expandExpectedAlertsVariables(URL_FIRST);
    assertEquals(getExpectedAlerts()[0], webDriver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlImageInput2Test.java

License:Apache License

/**
 * @throws Exception if the test fails// ww  w. j a v a 2s .  c om
 */
@Test
@Alerts("URL?imageInput.x=0&imageInput.y=0")
public void javascriptClick() throws Exception {
    final String html = "<html><head><title>foo</title>\n" + "</head><body>\n" + "<form>\n"
            + "  <input type='image' name='imageInput'>\n"
            + "  <input type='button' id='submit' value='submit' "
            + "onclick='document.getElementsByName(\"imageInput\")[0].click()'>\n" + "</form>\n"
            + "</body></html>";

    final WebDriver webDriver = loadPage2(html);
    webDriver.findElement(By.id("submit")).click();

    expandExpectedAlertsVariables(URL_FIRST);
    assertEquals(getExpectedAlerts()[0], webDriver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlImageInputTest.java

License:Apache License

/**
 * @throws Exception if the test fails// ww  w .j a v a2 s. c  o m
 */
@Test
@Alerts(DEFAULT = "URL?button.x=0&button.y=0", CHROME = "URL?button.x=9&button.y=7&button=foo", IE = "URL?button.x=14&button.y=15")
@NotYetImplemented({ CHROME, IE })
public void click_NoPosition() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='image' name='aButton' value='foo'/>\n"
            + "  <input type='image' name='button' value='foo'/>\n"
            + "  <input type='image' name='anotherButton' value='foo'/>\n" + "</form></body></html>";
    final WebDriver webDriver = loadPage2(html);
    webDriver.findElement(By.name("button")).click();

    expandExpectedAlertsVariables(URL_FIRST);
    assertEquals(getExpectedAlerts()[0], webDriver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlImageInputTest.java

License:Apache License

/**
 * @throws Exception if the test fails//from w ww  .ja  v a 2  s  .c  o  m
 */
@Test
@Alerts(DEFAULT = "URL?button.x=0&button.y=0", CHROME = "URL?button.x=22&button.y=7", IE = "URL?button.x=14&button.y=15")
@NotYetImplemented({ CHROME, IE })
public void click_NoPosition_NoValue() throws Exception {
    final String html = "<html><head><title>foo</title></head><body>\n" + "<form id='form1'>\n"
            + "  <input type='image' name='button'>\n" + "</form></body></html>";
    final WebDriver webDriver = loadPage2(html);
    webDriver.findElement(By.name("button")).click();

    expandExpectedAlertsVariables(URL_FIRST);
    assertEquals(getExpectedAlerts()[0], webDriver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlNoScriptTest.java

License:Apache License

/**
 * @throws Exception if the test fails// w w  w  .  j a  v a2s . co  m
 */
@Test
public void formValues() throws Exception {
    final String html = "<html><body>\n" + "<form name='item' method='get'>\n" + "  <noscript>\n"
            + "    <input type=hidden name='__webpage_no_js__' value='1'>\n" + "  </noscript>\n"
            + "  <input type=hidden name='myParam' value='myValue'>\n"
            + "  <input type='submit' id='clickMe'>\n" + "</form>\n" + "</body></html>";

    final WebDriver webDriver = loadPage2(html);
    webDriver.findElement(By.id("clickMe")).click();

    assertFalse(webDriver.getCurrentUrl().contains("__webpage_no_js__"));
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlPage3Test.java

License:Apache License

private void basePath(final String baseUrl, final String expected) throws Exception {
    final String html = "<html>\n" + "<head>\n" + "  <base href='" + baseUrl + "'>\n" + "</head>\n" + "<body>\n"
            + "  <a id='testLink' href='path'>click me</a>\n" + "</body></html>";
    final WebDriver webDriver = loadPage2(html, URL_SECOND);
    webDriver.findElement(By.id("testLink")).click();
    assertEquals(expected, webDriver.getCurrentUrl());
}