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.dom.CharacterDataTest.java

License:Apache License

/**
 * @throws Exception if the test fails//w ww  .j  av a 2 s . c  om
 */
@Test
@Alerts(DEFAULT = { "Some Not So New Te", "Some ", "So" }, IE = { "exception", "exception", "exception" })
public void deleteDataNegativeCount() throws Exception {
    final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n"
            + "  var div1=document.getElementById('div1');\n" + "  var text1=div1.firstChild;\n" + "  try {\n"
            + "    text1.deleteData(18, -15);\n" + "    alert(text1.data);\n"
            + "  } catch (e) { alert('exception') }\n"

            + "  try {\n" + "    text1.deleteData(5, -4);\n" + "    alert(text1.data);\n"
            + "  } catch (e) { alert('exception') }\n"

            + "  try {\n" + "    text1.deleteData(2, -4);\n" + "    alert(text1.data);\n"
            + "  } catch (e) { alert('exception') }\n" + "}\n" + "</script></head><body onload='doTest()'>\n"
            + "<div id='div1'>Some Not So New Text</div></body></html>";

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

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.CharacterDataTest.java

License:Apache License

/**
 * Regression test for insertData of a text node.
 * @throws Exception if the test fails//from   ww w  . j  a v a2  s . c  o  m
 */
@Test
@Alerts("Some New Text")
public void insertData() throws Exception {
    final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n"
            + "  var div1=document.getElementById('div1');\n" + "  var text1=div1.firstChild;\n"
            + "  text1.insertData(5, 'New ');\n" + "  alert(text1.data);\n" + "}\n"
            + "</script></head><body onload='doTest()'>\n" + "<div id='div1'>Some Text</div></body></html>";

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

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.CharacterDataTest.java

License:Apache License

/**
 * Regression test for replaceData of a text node.
 * @throws Exception if the test fails//from ww w  .  j  a va  2  s  .c o m
 */
@Test
@Alerts("Some New Text")
public void replaceData() throws Exception {
    final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n"
            + "  var div1=document.getElementById('div1');\n" + "  var text1=div1.firstChild;\n"
            + "  text1.replaceData(5, 3, 'New');\n" + "  alert(text1.data);\n" + "}\n"
            + "</script></head><body onload='doTest()'>\n" + "<div id='div1'>Some Old Text</div></body></html>";

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

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.CharacterDataTest.java

License:Apache License

/**
 * Regression test for substringData of a text node.
 * @throws Exception if the test fails/*from  w  ww.  ja  v  a  2 s .co  m*/
 */
@Test
@Alerts({ "New", "Some New Text" })
public void substringData() throws Exception {
    final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n"
            + "  var div1=document.getElementById('div1');\n" + "  var text1=div1.firstChild;\n"
            + "  alert(text1.substringData(5, 3));\n" + "  alert(text1.data);\n" + "}\n"
            + "</script></head><body onload='doTest()'>\n" + "<div id='div1'>Some New Text</div></body></html>";

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

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.CharacterDataTest.java

License:Apache License

/**
 * Regression test for substringData of a text node.
 * @throws Exception if the test fails//from w  w  w.  jav a 2 s.co m
 */
@Test
@Alerts({ "Some ", "Text", "true" })
public void textImpl_splitText() throws Exception {
    final String html = "<html><head><title>First</title><script>\n" + "function doTest() {\n"
            + "  var div1=document.getElementById('div1');\n" + "  var text1=div1.firstChild;\n"
            + "  var text2=text1.splitText(5);\n" + "  alert(text1.data);\n" + "  alert(text2.data);\n"
            + "  alert(text1.nextSibling==text2);\n" + "}\n" + "</script></head><body onload='doTest()'>\n"
            + "<div id='div1'>Some Text</div></body></html>";

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

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentTest.java

License:Apache License

/**
 * @throws Exception if the test fails/*from   w w  w. ja v a  2s . c om*/
 */
@Test
@Alerts({ "", "second" })
public void formArray() throws Exception {
    final String firstHtml = "<html><head><SCRIPT lang='JavaScript'>\n" + "function doSubmit(formName){\n"
            + "  var form = document.forms[formName];\n" + "  form.submit();\n" + "}\n"
            + "</SCRIPT></head><body><form name='formName' method='POST' " + "action='" + URL_SECOND + "'>\n"
            + "<a href='.' id='testJavascript' name='testJavascript' "
            + "onclick=\" doSubmit('formName');return false;\">\n"
            + "Test Link </a><input type='submit' value='Login' " + "name='loginButton'></form>\n"
            + "</body></html> ";
    final String secondHtml = "<html><head><title>second</title></head><body>\n" + "<p>hello world</p>\n"
            + "</body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondHtml);

    expandExpectedAlertsVariables(URL_FIRST);
    final WebDriver driver = loadPage2(firstHtml);
    assertEquals(getExpectedAlerts()[0], driver.getTitle());

    driver.findElement(By.id("testJavascript")).click();
    assertEquals(getExpectedAlerts()[1], driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentTest.java

License:Apache License

/**
 * Test setting and reading the title for an existing title.
 * @throws Exception if the test fails/*w w  w. jav a 2  s. co m*/
 */
@Test
@Alerts("correct title")
public void settingTitle() throws Exception {
    final String html = "<html><head><title>Bad Title</title></head>\n" + "<body>\n" + "<script>\n"
            + "  document.title = 'correct title';\n" + "  alert(document.title);\n" + "</script>\n"
            + "</body></html>";

    final WebDriver driver = loadPageWithAlerts2(html);
    assertEquals(getExpectedAlerts()[0], driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentTest.java

License:Apache License

/**
 * Test setting and reading the title for when the is not in the page to begin.
 * @throws Exception if the test fails//from w w  w  . j a v  a2  s .  c  o  m
 */
@Test
@Alerts("correct title")
public void settingBlankTitle() throws Exception {
    final String html = "<html><head><title></title></head>\n" + "<body>\n" + "<script>\n"
            + "  document.title = 'correct title';\n" + "  alert(document.title);\n" + "</script>\n"
            + "</body></html>";

    final WebDriver driver = loadPageWithAlerts2(html);
    assertEquals(getExpectedAlerts()[0], driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.DocumentTest.java

License:Apache License

/**
 * @throws Exception if the test fails/*  w w  w  . jav  a  2s  .co m*/
 */
@Test
@Alerts("foo")
public void title() throws Exception {
    final String html = "<html><head><title>foo</title><script>\n" + "function doTest() {\n"
            + "  alert(document.title);\n" + "}\n" + "</script></head>\n" + "<body onload='doTest()'>\n"
            + "</body></html>";

    final WebDriver driver = loadPageWithAlerts2(html);
    assertEquals(getExpectedAlerts()[0], driver.getTitle());
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.event.MouseEventTest.java

License:Apache License

private void eventCoordinates(final String id) throws Exception {
    final String html = getFileContent("event_coordinates.html");

    final String[] expected = getExpectedAlerts();

    setExpectedAlerts();/* w  w w .  ja v a  2  s . co m*/
    final WebDriver driver = loadPageWithAlerts2(html);
    assertEquals("Mouse Event coordinates", driver.getTitle());

    final WebElement textarea = driver.findElement(By.id("myTextarea"));
    assertEquals("", textarea.getText());

    driver.findElement(By.id(id)).click();
    assertEquals(expected[0], textarea.getAttribute("value").trim());
}