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.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

/***
 * Waits the till element is displayed//from w ww  .jav a2  s.  co  m
 * 
 * @param driver
 * @param elementNameOrID
 */
public static WebElement waitForElement(WebDriver driver, String elementNameOrID, long timeout) {
    long start = System.currentTimeMillis();
    WebElement webElement = null;
    while (null == webElement) {
        webElement = getByNameOrID(driver, elementNameOrID);
        if (null != webElement)
            break;
        Assert.assertTrue("Timeout (>" + timeout + "ms) while waiting for web element " + elementNameOrID
                + " in page '" + driver.getTitle() + "'", System.currentTimeMillis() - start < timeout);
        waitForASecond();
    }
    return webElement;
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

public static WebElement waitForSelectElement(WebDriver driver, String elementNameOrID, String optionValue,
        long timeout) {
    long start = System.currentTimeMillis();
    WebElement webElement = null;/*w  w  w.j  ava  2s  .c  om*/
    while (null == webElement) {
        webElement = getSelectOptionByValue(driver, elementNameOrID, optionValue);
        if (null != webElement)
            break;
        Assert.assertTrue("Timeout (>" + timeout + "ms) while waiting for select web element " + elementNameOrID
                + " in page '" + driver.getTitle() + "'", System.currentTimeMillis() - start < timeout);
        waitForASecond();
    }
    return webElement;
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

public static WebElement waitForEnabled(WebDriver driver, String elementNameOrID, long timeout) {
    long start = System.currentTimeMillis();
    WebElement webElement = null;/*  ww w. ja v a  2  s.c o  m*/
    while (null == webElement || !webElement.isEnabled()) {
        webElement = getByNameOrID(driver, elementNameOrID);
        if (null != webElement && webElement.isEnabled())
            break;
        Assert.assertTrue(
                "Timeout (>" + timeout + "ms) while waiting for web element " + elementNameOrID
                        + " to be enabled in page '" + driver.getTitle() + "'",
                System.currentTimeMillis() - start < timeout);
        waitForASecond();
    }
    return webElement;
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

public static WebElement waitForInputElementByTypeAndValue(WebDriver driver, String type, String value,
        long timeout) {
    long start = System.currentTimeMillis();
    WebElement webElement = null;/*w w  w .  j  a v  a2s  . co m*/

    while (null == webElement) {
        try {
            webElement = getInputItemByTypeAndValue(driver, type, value);
        } catch (Exception ex) {

        }
        if (null != webElement)
            break;
        Assert.assertTrue(
                "Timeout (>" + timeout + "ms) while waiting for input element type " + type + " to have value "
                        + value + " in page '" + driver.getTitle() + "'",
                System.currentTimeMillis() - start < timeout);
        waitForASecond();
    }
    return webElement;
}

From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java

License:Apache License

/***
 * Waits till the title is displayed//w  ww .j  a  v a2  s  . c o m
 * 
 * @param driver
 * @param title
 */
public static void waitForTitle(WebDriver driver, String title, long timeout) {
    long start = System.currentTimeMillis();
    String pageTitle = null;
    while (StringUtils.isBlank(pageTitle) || !StringUtils.equals(pageTitle, title)) {
        try {
            pageTitle = driver.getTitle();
        } catch (Exception ex) {

        }
        if (StringUtils.isNotBlank(pageTitle) && StringUtils.equals(pageTitle, title))
            break;
        Assert.assertTrue("Timeout (>" + timeout + "ms) while waiting for title to be set to '" + title
                + "' in page '" + driver.getTitle() + "'", System.currentTimeMillis() - start < timeout);
        waitForASecond();
    }
}

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

License:Apache License

/**
 * @exception Exception If the test fails
 */// ww w .  ja va 2s . c  o m
@Test
@BuggyWebDriver(IE)
public void shiftClick() throws Exception {
    final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND
            + "'>Click Me</a>\n" + "</form></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
    final WebDriver driver = loadPage2(html);

    final WebElement link = driver.findElement(By.linkText("Click Me"));

    final String originalTitle = driver.getTitle();

    final int windowsSize = driver.getWindowHandles().size();

    new Actions(driver).moveToElement(link).keyDown(Keys.SHIFT).click().keyUp(Keys.SHIFT).perform();

    assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size());
    assertEquals("Should not have navigated away", originalTitle, driver.getTitle());
}

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

License:Apache License

/**
 * @exception Exception If the test fails
 *//*ww  w  .j  av  a2  s.co  m*/
@Test
@BuggyWebDriver({ IE, FF })
public void ctrlClick() throws Exception {
    final String html = "<html><head><title>First</title></head><body>\n" + "<a href='" + URL_SECOND
            + "'>Click Me</a>\n" + "</form></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, "<head><title>Second</title>");
    final WebDriver driver = loadPage2(html);

    final WebElement link = driver.findElement(By.linkText("Click Me"));

    final String originalTitle = driver.getTitle();

    final int windowsSize = driver.getWindowHandles().size();

    new Actions(driver).moveToElement(link).keyDown(Keys.CONTROL).click().keyUp(Keys.CONTROL).perform();

    assertEquals("Should have opened a new window", windowsSize + 1, driver.getWindowHandles().size());
    assertEquals("Should not have navigated away", originalTitle, driver.getTitle());
}

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

License:Apache License

/**
 * According to the HTML spec, the default type for a button is "submit".
 * IE is different than the HTML spec and has a default type of "button".
 * @throws Exception if the test fails//  w ww . j a  va 2s.  co m
 */
@Test
@Alerts({ "submit", "1", "button-pushme", "Second" })
public void defaultButtonType_StandardsCompliantBrowser() throws Exception {
    final String firstContent = "<html><head><title>First</title></head><body>\n" + "<form id='form1' action='"
            + URL_SECOND + "' method='post'>\n"
            + "  <button name='button' id='button' value='pushme'>PushMe</button>\n" + "</form></body></html>";
    final String secondContent = "<html><head><title>Second</title></head><body'></body></html>";

    getMockWebConnection().setResponse(URL_SECOND, secondContent);

    final WebDriver driver = loadPage2(firstContent);
    final WebElement button = driver.findElement(By.id("button"));

    assertEquals(getExpectedAlerts()[0], button.getAttribute("type"));

    button.click();

    final List<NameValuePair> params = getMockWebConnection().getLastParameters();
    assertEquals(getExpectedAlerts()[1], "" + params.size());

    if (params.size() > 0) {
        assertEquals(getExpectedAlerts()[2], params.get(0).getName() + "-" + params.get(0).getValue());
    }
    assertEquals(getExpectedAlerts()[3], driver.getTitle());
}

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

License:Apache License

/**
 * @throws Exception if the test fails//  ww w  .  j  av  a  2  s.  c  o m
 */
@Test
@Alerts(DEFAULT = { "2", "second" }, IE = { "1", "first" })
public void externalPreferenceFrom() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm2' action='" + URL_SECOND + "'>\n" + "  </form>\n"
            + "  <form id='myForm3' action='" + URL_THIRD + "'>\n"
            + "    <button type='submit' id='myButton' form='myForm2'>Explicit Submit</button>\n"
            + "  </form>\n" + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";
    final String thirdContent = "<html><head><title>third</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

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

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    assertEquals(getExpectedAlerts()[1], driver.getTitle());

    shutDownRealIE();
}

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

License:Apache License

/**
 * @throws Exception if the test fails/*from  w ww . j  a va2s. com*/
 */
@Test
@Alerts(DEFAULT = { "2", "second" }, IE = { "1", "first" })
public void internalDifferentFrom() throws Exception {
    final String html = "<html><head><title>first</title></head><body>\n" + "  <p>hello world</p>\n"
            + "  <form id='myForm' action='" + URL_SECOND + "'>\n" + "  </form>\n"
            + "  <form id='other' action='" + URL_THIRD + "'>\n"
            + "    <button type='submit' id='myButton' form='myForm'>Explicit Submit</button>\n" + "  </form>\n"
            + "</body></html>";
    final String secondContent = "<html><head><title>second</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";
    final String thirdContent = "<html><head><title>third</title></head><body>\n" + "  <p>hello world</p>\n"
            + "</body></html>";

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

    final WebDriver driver = loadPage2(html);
    driver.findElement(By.id("myButton")).click();

    final int expectedReqCount = Integer.parseInt(getExpectedAlerts()[0]);
    assertEquals(expectedReqCount, getMockWebConnection().getRequestCount());
    assertEquals(getExpectedAlerts()[1], driver.getTitle());
}