Example usage for org.openqa.selenium WebDriver getTitle

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

Introduction

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

Prototype

String getTitle();

Source Link

Document

Get the title of the current page.

Usage

From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java

License:Apache License

/**
 * Test for <tt>replace</tt>.
 * @throws Exception if the test fails// w  w  w.j a v  a  2  s.  c  om
 */
@Test
@Alerts("on-load")
public void replaceOnload() throws Exception {
    final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n"
            + "  location.replace('" + URL_SECOND + "');\n" + "}\n" + "</script></head>\n"
            + "<body onload='doTest()'>\n" + "</body></html>";

    final String secondContent = "<html><head><title>Second</title></head>\n"
            + "<body onload='alert(\"on-load\")'></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    final WebDriver webdriver = loadPageWithAlerts2(html);

    assertEquals("Second", webdriver.getTitle());
    assertEquals(2, getMockWebConnection().getRequestCount());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java

License:Apache License

/**
 * Test for <tt>replace</tt>.
 * @throws Exception if the test fails/*from   w w  w .  j ava2s  . c o m*/
 */
@Test
public void replaceFirstInHistory() throws Exception {
    final String firstContent = "<html><head><title>First Page</title><script>\n" + "function doTest() {\n"
            + "  location.replace('" + URL_SECOND + "');\n" + "}\n"
            + "</script></head><body onload='doTest()'>\n" + "</body></html>";

    final String secondContent = "<html><head><title>Second Page</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver webdriver = loadPageWithAlerts2(firstContent);

    assertEquals("Second Page", webdriver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   www.ja v  a  2s.  c  o m*/
 */
@Test
public void assign() throws Exception {
    final String firstContent = "<html><head><title>First</title><script>\n" + "  function test() {\n"
            + "    location.assign('" + URL_SECOND + "');\n" + "  }\n"
            + "</script></head><body onload='test()'>\n" + "</body></html>";

    final String secondContent = "<html><head><title>Second</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(firstContent, URL_FIRST);
    assertEquals("Second", driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   w  w w.j a  v  a2  s .  c  om*/
 */
@Test
@Alerts("on-load")
public void assignOnload() throws Exception {
    final String firstContent = "<html><head><title>First</title><script>\n" + "  function test() {\n"
            + "    location.assign('" + URL_SECOND + "');\n" + "  }\n" + "</script></head>\n"
            + "<body onload='test()'>\n" + "</body></html>";

    final String secondContent = "<html><head><title>Second</title></head>\n"
            + "<body onload='alert(\"on-load\");'></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    final WebDriver driver = loadPageWithAlerts2(firstContent);

    assertEquals("Second", driver.getTitle());
    assertEquals(2, getMockWebConnection().getRequestCount());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from w w w  .j a  v a 2 s .  c om
 */
@Test
public void assingByEquals() throws Exception {
    final String firstContent = "<html><head><title>First</title><script>\n" + "  function test() {\n"
            + "    location = '" + URL_SECOND + "';\n" + "  }\n" + "</script></head><body onload='test()'>\n"
            + "</body></html>";

    final String secondContent = "<html><head><title>Second</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(firstContent, URL_FIRST);
    assertEquals("Second", driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Location2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from www  .  j ava  2  s . com
 */
@Test
@Alerts("on-load")
public void assingByEqualsOnload() throws Exception {
    final String firstContent = "<html><head><title>First</title><script>\n" + "  function test() {\n"
            + "    location  = '" + URL_SECOND + "';\n" + "  }\n" + "</script></head>\n"
            + "<body onload='test()'>\n" + "</body></html>";

    final String secondContent = "<html><head><title>Second</title></head>\n"
            + "<body onload='alert(\"on-load\");'></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    final WebDriver driver = loadPageWithAlerts2(firstContent);

    assertEquals("Second", driver.getTitle());
    assertEquals(2, getMockWebConnection().getRequestCount());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Window2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//w w w. j a  va  2  s . c  o m
 */
@Test
public void setLocation() throws Exception {
    final String firstContent = "<html>\n" + "<head><title>First</title></head>\n" + "<body>\n"
            + "<form name='form1'>\n" + "  <a id='link' onClick='location=\"" + URL_SECOND
            + "\";'>Click me</a>\n" + "</form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>Second</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(firstContent);
    assertEquals("First", driver.getTitle());
    assertEquals(1, driver.getWindowHandles().size());

    driver.findElement(By.id("link")).click();
    assertEquals("Second", driver.getTitle());

    assertEquals(1, driver.getWindowHandles().size());
    assertEquals(new String[] { "", "second/" }, getMockWebConnection().getRequestedUrls(URL_FIRST));
    assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Window2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//from  w  w w.  j  a  v a 2 s . co  m
 */
@Test
public void setWindowLocation() throws Exception {
    final String firstContent = "<html>\n" + "<head><title>First</title></head>\n" + "<body>\n"
            + "<form name='form1'>\n" + "  <a id='link' onClick='window.location=\"" + URL_SECOND
            + "\";'>Click me</a>\n" + "</form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>Second</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(firstContent);
    assertEquals("First", driver.getTitle());
    assertEquals(1, driver.getWindowHandles().size());

    driver.findElement(By.id("link")).click();
    assertEquals("Second", driver.getTitle());

    assertEquals(1, driver.getWindowHandles().size());
    assertEquals(new String[] { "", "second/" }, getMockWebConnection().getRequestedUrls(URL_FIRST));
    assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Window2Test.java

License:Apache License

/**
 * @throws Exception if the test fails//  w w  w . ja v a2 s . c om
 */
@Test
public void setDocumentLocation() throws Exception {
    final String firstContent = "<html>\n" + "<head><title>First</title></head>\n" + "<body>\n"
            + "<form name='form1'>\n" + "  <a id='link' onClick='document.location=\"" + URL_SECOND
            + "\";'>Click me</a>\n" + "</form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>Second</title></head><body></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(firstContent);
    assertEquals("First", driver.getTitle());
    assertEquals(1, driver.getWindowHandles().size());

    driver.findElement(By.id("link")).click();
    assertEquals("Second", driver.getTitle());

    assertEquals(1, driver.getWindowHandles().size());
    assertEquals(new String[] { "", "second/" }, getMockWebConnection().getRequestedUrls(URL_FIRST));
    assertEquals(URL_SECOND.toString(), driver.getCurrentUrl());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.Window3Test.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   ww  w. jav  a2  s. co  m*/
 */
@Test
@Alerts({ "null", "one", "two", "three" })
@BuggyWebDriver(IE)
public void opener() throws Exception {
    final URL urlThird = new URL(URL_FIRST, "third/");

    final String firstContent = HtmlPageTest.STANDARDS_MODE_PREFIX_
            + "<html><head><title>First</title><script>\n" + "function test() {\n" + "  alert(window.opener);\n"
            + "  alert('one');\n" + "  open('" + URL_SECOND + "', 'foo');\n" + "}\n"
            + "function callAlert(text) {\n" + "  alert(text);\n" + "}\n"
            + "</script></head><body onload='test()'>\n" + "</body></html>";
    final String secondContent = HtmlPageTest.STANDARDS_MODE_PREFIX_
            + "<html><head><title>Second</title><script>\n" + "function test() {\n"
            + "  opener.callAlert('two');\n" + "  document.form1.submit();\n" + "}\n"
            + "</script></head><body onload='test()'>\n" + "<form name='form1' action='" + urlThird
            + "' method='post'><input type='submit'></form>\n" + "</body></html>";
    final String thirdContent = HtmlPageTest.STANDARDS_MODE_PREFIX_
            + "<html><head><title>Third</title><script>\n" + "function test() {\n"
            + "  opener.callAlert('three');\n" + "}\n" + "</script></head><body onload='test()'>\n"
            + "</body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);
    getMockWebConnection().setResponse(urlThird, thirdContent);

    final WebDriver driver = loadPageWithAlerts2(firstContent);
    assertEquals("First", driver.getTitle());
}