Example usage for org.openqa.selenium By id

List of usage examples for org.openqa.selenium By id

Introduction

In this page you can find the example usage for org.openqa.selenium By id.

Prototype

public static By id(String id) 

Source Link

Usage

From source file:be.rubus.web.jerry.interceptor.RendererInterceptorTest.java

License:Apache License

@Test
@RunAsClient//from  w  w  w  .  j  a  va2s . c o  m
public void testInterceptor() throws Exception {
    driver.get(new URL(contextPath, "page.xhtml").toString());

    WebElement inputField = driver.findElement(By.id("test:valueInput"));
    String styleClass = inputField.getAttribute("class");
    assertThat(styleClass).isEqualTo("inputField");
}

From source file:be.rubus.web.jerry.recording.RecordValueTest.java

License:Apache License

@Test
@RunAsClient/*from w ww. j a  v  a 2  s.c om*/
public void testClassLevelValidation() throws Exception {
    driver.get(new URL(contextPath, "dateRange.xhtml").toString());

    WebElement field = driver.findElement(By.id("test:beginDate"));
    field.sendKeys("01/03/2015");

    field = driver.findElement(By.id("test:endDate"));
    field.sendKeys("01/01/2015");

    WebElement submitButton = driver.findElement(By.id("test:submit"));
    submitButton.click();

    Thread.sleep(1000);

    WebElement messages = driver.findElement(By.id("errors"));
    List<WebElement> errorElements = messages.findElements(By.tagName("li"));

    // FIXME The test fails and it seems that RecordingInfoPhaseListener doesn't kick in
    assertThat(errorElements).hasSize(1);

    assertThat(errorElements.get(0).getText()).contains("Validation Error: Value is required.");

}

From source file:be.rubus.web.jerry.validation.CombinedTest.java

License:Apache License

@Test
@RunAsClient/* w w  w .j  a v a  2  s .c o  m*/
public void testCombined() throws Exception {
    driver.get(new URL(contextPath, "combined.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:value"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:valueLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("value");

    element = driver.findElement(By.id("test:required"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:requiredLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("required*");

    element = driver.findElement(By.id("test:maxLength"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("14");

    element = driver.findElement(By.id("test:maxLengthLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("max length");

    element = driver.findElement(By.id("test:combined"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("14");

    element = driver.findElement(By.id("test:combinedLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("combined*");

}

From source file:be.rubus.web.jerry.validation.CustomTest.java

License:Apache License

@Test
@RunAsClient/*from ww w  .j av a 2 s  .com*/
public void testCustom() throws Exception {
    driver.get(new URL(contextPath, "custom.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:zipCodeMaskLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("Zip code (mask)*");

    element = driver.findElement(By.id("test:zipCode"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("4");

    element = driver.findElement(By.id("test:zipCodeMask"));

    element.sendKeys("azer");
    // Only numbers allowed in the mask
    assertThat(element.getAttribute("value")).isEqualTo("____");

    element.clear();
    element.sendKeys("12345");
    // Only 4 numbers allowed in the mask
    assertThat(element.getAttribute("value")).isEqualTo("1234");

}

From source file:be.rubus.web.jerry.validation.FutureDateProviderTest.java

License:Apache License

@Test
@RunAsClient//  w  w  w .j a va 2  s.com
public void testFuture() throws Exception {
    driver.get(new URL(contextPath, "future.xhtml").toString());

    //By default, the date provider is using system date, so failures
    WebElement date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    WebElement date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    assertThat(date1.getAttribute("class")).doesNotContain("ui-state-error");
    assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error");

    WebElement btn = driver.findElement(By.id("test:submit"));
    btn.click();

    WebElement errors = driver.findElement(By.id("errors"));

    List<WebElement> errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(2);

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).contains("ui-state-error");

    // Set date for DateProvider
    WebElement fixedNow = driver.findElement(By.id("date:fixedNow"));
    fixedNow.clear();
    fixedNow.sendKeys("20/02/2015");

    WebElement dateBtn = driver.findElement(By.id("date:setDate"));
    dateBtn.click();

    date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    btn = driver.findElement(By.id("test:submit"));
    btn.click();

    errors = driver.findElement(By.id("errors"));

    errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(1); // Only 1 error now

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); // The one withValFuture

}

From source file:be.rubus.web.jerry.validation.FutureTest.java

License:Apache License

@Test
@RunAsClient//www.  jav a 2 s.  c om
public void testFuture() throws Exception {
    driver.get(new URL(contextPath, "future_NoProvider.xhtml").toString());

    WebElement date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    WebElement date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    WebElement btn = driver.findElement(By.id("test:submit"));
    btn.click();

    WebElement errors = driver.findElement(By.id("errors"));

    List<WebElement> errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(2);

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).contains("ui-state-error");
}

From source file:be.rubus.web.jerry.validation.MaxSizeTest.java

License:Apache License

@Test
@RunAsClient//  w ww . j av a 2  s. c  o m
public void testMaxLength() throws Exception {
    driver.get(new URL(contextPath, "maxSize.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:default"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:value"));
    assertThat(element.getAttribute("maxlength")).isNull();

    element = driver.findElement(By.id("test:standard"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("5");

    element = driver.findElement(By.id("test:maxLength"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("5");

    element = driver.findElement(By.id("test:special"));
    assertThat(element.getAttribute("maxlength")).isEqualTo("7");

}

From source file:be.rubus.web.jerry.validation.MaxSizeTest.java

License:Apache License

@Test
@RunAsClient/*from  ww w  .  j a  v a  2 s. c  om*/
public void testMaxLength_TextArea() throws Exception {
    driver.get(new URL(contextPath, "maxSize_TextArea.xhtml").toString());

    WebElement element = driver.findElement(By.id("frm:description"));

    WebElement remaining = driver.findElement(By.id("frm:remaining"));
    assertThat(remaining.getText()).contains("10");

    element.sendKeys("abcde");
    assertThat(remaining.getText()).contains("5");

    element.sendKeys("abcdefghijk");
    assertThat(remaining.getText()).contains("0");

    assertThat(element.getAttribute("value")).isEqualTo("abcdeabcde");

}

From source file:be.rubus.web.jerry.validation.RequiredTest.java

License:Apache License

@Test
@RunAsClient/*from  w w w.  ja  v a 2 s.com*/
public void testRequired() throws Exception {
    driver.get(new URL(contextPath, "required.xhtml").toString());

    WebElement element = driver.findElement(By.id("test:notRequiredLabel"));
    String text = element.getText();
    assertThat(text).isEqualTo("notRequired");

    element = driver.findElement(By.id("test:requiredLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("required*");

    element = driver.findElement(By.id("test:sizeLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("size");

    element = driver.findElement(By.id("test:specialLabel"));
    text = element.getText();
    assertThat(text).isEqualTo("special*");

}

From source file:be.ugent.mmlab.webdriver.Demo.java

License:Apache License

public void demoTime() throws InterruptedException {
    // initialize web browser.
    WebDriver driver = new FirefoxDriver();

    // go to the Belgian railways website
    driver.get("http://www.belgianrail.be");

    // select "English"
    // HTML:/*  ww  w  . j av a2 s.  co m*/
    // <a
    //   id="ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink"
    //   href="javascript:__doPostBack('ctl00$bodyPlaceholder$languagesList$ctl02$languageNameLink','')"
    // > English </a>
    WebElement english = driver
            .findElement(By.id("ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink"));
    english.click();

    // fill out departure
    WebElement from = driver.findElement(By.id("departureStationInput"));
    from.sendKeys("Gent-Dampoort");

    // pause for a second to make it not too fast
    Thread.sleep(1000);
    // click in the field to get the auto-completion away
    from.click();

    // fill out arrival
    WebElement to = driver.findElement(By.id("arrivalStationInput"));
    to.sendKeys("Brussel-Noord");

    Thread.sleep(1000);
    to.click();

    // click timetable button
    WebElement timetableButton = driver.findElement(By.id(
            "ctl00_ctl00_bodyPlaceholder_bodyPlaceholder_mobilityTimeTableSearch_HomeTabTimeTable1_submitButton"));
    timetableButton.click();

    // get departure info
    // HTML:
    // <td headers="hafasOVTimeOUTWARD" class="time">
    //    <div>
    //     <div class="planed overviewDep">
    //      10:00 dep <span class="bold prognosis">+12 min.</span>
    //     </div>
    //     <div class="planed">
    //      11:20 arr <span class="bold green">+0 min.</span>
    //     </div>
    //   </div>
    // </td>
    List<WebElement> timeCells = driver.findElements(By.className("time"));
    for (WebElement timeCell : timeCells) {
        List<WebElement> times = timeCell.findElements(By.className("planed"));
        System.out.println("----------------------------------------------");
        System.out.println("departure time: " + times.get(0).getText());
        System.out.println("arrival time:   " + times.get(1).getText());
    }
}