Example usage for org.openqa.selenium Keys ENTER

List of usage examples for org.openqa.selenium Keys ENTER

Introduction

In this page you can find the example usage for org.openqa.selenium Keys ENTER.

Prototype

Keys ENTER

To view the source code for org.openqa.selenium Keys ENTER.

Click Source Link

Usage

From source file:com.opera.core.systems.FormSubmissionTest.java

License:Apache License

@Test
public void keysEnterSubmitsForm() {
    input.sendKeys("foo", Keys.ENTER);
    assertPassed();
}

From source file:com.opera.core.systems.IdleTest.java

License:Apache License

@Test
@Ignore//from   w  w w  . java  2 s. co m
public void testKeyEnter() {
    getFixture("javascript.html");

    // Focus textbox
    driver.findElementById("one").click();

    // submit form
    start();
    new Actions(driver).sendKeys(Keys.ENTER).build().perform();
    stop();

    // +"?" for submitted query string
    assertTrue(driver.getCurrentUrl().endsWith("test.html?"));
}

From source file:com.pentaho.ctools.cdf.DateInputComponent.java

License:Apache License

/**
 * ############################### Test Case 1 ###############################
 *
 * Test Case Name://  w  w w . ja v a2 s. c  o  m
 *    DateInputComponent
 * Description:
 *    We pretend to check the component when user pick a data an alert message
 *    is displayed indicating the date picked.
 * Steps:
 *    1. Go to Pentaho solution web page.
 *    2. Render the component again.
 *    3. Choose the date '2011-10-23'.
 */
@Test
public void tc1_DataInput_DisplayPopupWithPickedDate() {
    this.log.info("tc1_DataInput_DisplayPopupWithPickedDate");
    /*
     * ## Step 1
     */
    driver.get(PageUrl.DATEINPUT_COMPONENT);

    //NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));

    //Wait for visibility of 'DateInputComponent'
    this.elemHelper.WaitForElementVisibility(driver,
            By.xpath("//div[@id='dashboardContent']/div/div/div/h2/span[2]"));
    // Validate the sample that we are testing is the one
    assertEquals("Community Dashboard Framework", driver.getTitle());
    assertEquals("DateInputComponent", this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='dashboardContent']/div/div/div/h2/span[2]")));

    /*
     * ## Step 2
     */
    //Render again the sample
    this.elemHelper.ClickJS(driver, By.xpath("//div[@id='example']/ul/li[2]/a"));
    this.elemHelper.ClickJS(driver, By.xpath("//div[@id='code']/button"));
    //NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Now sample element must be displayed
    assertTrue(this.elemHelper.FindElement(driver, By.id("sample")).isDisplayed());

    /*
     * ## Step 3
     */
    //Pick a date
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("myInput"));
    this.elemHelper.FindElement(driver, By.id("myInput")).sendKeys("''");

    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("ui-datepicker-div"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.className("ui-datepicker-month"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.className("ui-datepicker-year"));
    Select month = new Select(this.elemHelper.FindElement(driver, By.className("ui-datepicker-month")));
    month.selectByValue("9");
    Select year = new Select(this.elemHelper.FindElement(driver, By.className("ui-datepicker-year")));
    year.selectByValue("2011");
    //Day 23
    this.elemHelper.FindElement(driver, By.xpath("//table[@class='ui-datepicker-calendar']//tbody//tr[5]/td/a"))
            .sendKeys(Keys.ENTER);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();

    /*##########################################################################
      EXPECTED RESULT:
      - The popup alert shall displayed the data picked.
     #########################################################################*/
    assertEquals(confirmationMsg, "You chose: 2011-10-23");
}

From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 3 ###############################
 *
 * Test Case Name:// w  w  w  .j  ava2 s .  c o  m
 *    Set Date Range Today
 * Description:
 *    When click on Today option an alert is displayed with today date in
 *    range interval.
 * Steps:
 *    1. Click in Today option
 *    2. Check for Alert
 */
@Test
public void tc3_Today_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Today")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strToday + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 4 ###############################
 *
 * Test Case Name:/* ww  w.  j  a v  a 2 s .  c  o m*/
 *    Set Date Range for the Last Seven Days.
 * Description:
 *    When click on Last 7 Days option an alert is displayed with 7 days
 *    before today and the today date.
 * Steps:
 *    1. Click in Last 7 Days option
 *    2. Check for Alert
 */
@Test
public void tc4_LastSevenDays_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Last 7 days")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DAY_OF_MONTH, -7);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + sdf.format(c.getTime()) + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 5 ###############################
 *
 * Test Case Name:/*from  w  ww  .ja v  a  2 s  . co m*/
 *    Set Date Range Month to Today date
 * Description:
 *    When click on Month to date option an alert is displayed with begin
 *    month day to today date.
 * Steps:
 *    1. Click in Month to date option
 *    2. Check for Alert
 */
@Test
public void tc5_MonthToDate_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Month to date")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);
    String strCurrentMonth = sdfMonth.format(dNow) + "-01";

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strCurrentMonth + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 6 ###############################
 *
 * Test Case Name://from   ww  w . jav a2  s  .c o m
 *    Set Date Range Year To Date
 * Description:
 *    When click on Year To Date option an alert is displayed with begin year
 *    date to today date in range interval.
 * Steps:
 *    1. Click in Year to date option
 *    2. Check for Alert
 */
@Test
public void tc6_YearToDate_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("Year to date")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
    Date dNow = new Date();
    String strToday = sdf.format(dNow);
    String strBeginYear = sdfYear.format(dNow) + "-01-01";

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strBeginYear + " to " + strToday;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 7 ###############################
 *
 * Test Case Name://www . j a  va 2 s.co  m
 *    Set Date Range Today
 * Description:
 *    When click on The Previous Month option an alert is displayed with the
 *    start day of previous month to last day of previous month in range
 *    interval.
 * Steps:
 *    1. Click in The Previous Month option
 *    2. Check for Alert
 */
@Test
public void tc7_ThePreviousMonth_DateIsSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("The previous Month")).sendKeys(Keys.ENTER);

    /*
     * ## Step 2
     */
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MONTH, -1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");

    String strLastMonthEndDay = sdf.format(c.getTime());
    String strLastMonthStartDay = sdf.format(c.getTime()) + "-01";
    c.add(Calendar.MONTH, 1);
    c.add(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) * -1);
    strLastMonthEndDay += "-" + c.get(Calendar.DAY_OF_MONTH);

    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    String expectedCnfText = "You chose from " + strLastMonthStartDay + " to " + strLastMonthEndDay;
    alert.accept();

    assertEquals(confirmationMsg, expectedCnfText);
}

From source file:com.pentaho.ctools.cdf.DateRangeInputComponent.java

License:Apache License

/**
 * ############################### Test Case 8 ###############################
 *
 * Test Case Name://  ww w. j a va  2  s  . c  om
 *    Set Date Range Today
 * Description:
 *    When click on All Dates Before option an alert is displayed with an 
 *    interval starting from '2014-04-22'  to the selected date.
 * Steps:
 *    1. Click in Today option and then Cancel
 *    2. Click in Today option and then Done
 *    3. Check for Alert
 */
@Test
public void tc8_AllDatesBeforePressCancelAndSelectDate_DateIsCancelAndThenSetSuccessful() {
    /*
     * ## Step 1
     */
    this.elemHelper.Click(driver, By.id("myInput"));
    this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER);
    this.elemHelper.Click(driver, By.xpath("(//button[contains(text(),'Cancel')])[7]"));
    this.elemHelper.WaitForElementInvisibility(driver, By.xpath("(//a[text()='All Dates Before'])[2]"), 5);
    WebElement dataPickerDisable = this.elemHelper.WaitForElementPresence(driver,
            By.xpath("(//a[text()='All Dates Before'])[2]"), 1);
    assertFalse(dataPickerDisable.isDisplayed());

    /*
     * ## Step 2
     */
    //Click in day 29
    this.elemHelper.Click(driver, By.id("myInput"));
    //ADD THIS LINE TO RUN IN WIN8: this.elemHelper.Click( driver, By.id( "myInput2" ) );
    this.elemHelper.FindElement(driver, By.linkText("All Dates Before")).sendKeys(Keys.ENTER);
    this.elemHelper.FindElement(driver, By.linkText("29")).sendKeys(Keys.ENTER);

    /*
     * ## Step 3
     */
    wait.until(ExpectedConditions.alertIsPresent());
    Alert alert = driver.switchTo().alert();
    String confirmationMsg = alert.getText();
    alert.accept();

    Calendar c = Calendar.getInstance();
    c.add(Calendar.YEAR, -1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    String beginDate = sdf.format(c.getTime());

    assertEquals("You chose from " + beginDate + " to 2014-09-29", confirmationMsg);
}

From source file:com.pentaho.ctools.cdf.require.DateInputComponent.java

License:Apache License

/**
 * ############################### Test Case 1 ###############################
 *
 * Test Case Name:// w  w w  . ja  va 2s  .c  o m
 *    DateInputComponent
 * Description:
 *    We pretend to check the component when user pick a data an alert message
 *    is displayed indicating the date picked.
 * Steps:
 *    1. Go to Pentaho solution web page.
 *    2. Render the component again.
 *    3. Choose the date '2011-10-23'.
 */
@Test
public void tc1_DataInput_DisplayPopupWithPickedDate() {
    this.log.info("tc1_DataInput_DisplayPopupWithPickedDate");
    /*
     * ## Step 1
     */
    driver.get(PageUrl.DATEINPUT_COMPONENT_REQUIRE);

    //NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementPresence(driver, By.cssSelector("div.blockUI.blockOverlay"), 5);
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));

    //Wait for visibility of 'DateInputComponent'
    this.elemHelper.WaitForElementVisibility(driver,
            By.xpath("//div[@id='dashboardContent']/div/div/div/h2/span[2]"));
    // Validate the sample that we are testing is the one
    assertEquals("Community Dashboard Framework", driver.getTitle());
    assertEquals("DateInputComponent", this.elemHelper.WaitForElementPresentGetText(driver,
            By.xpath("//div[@id='dashboardContent']/div/div/div/h2/span[2]")));

    /*
     * ## Step 2
     */
    //Render again the sample
    this.elemHelper.ClickJS(driver, By.xpath("//div[@id='example']/ul/li[2]/a"));
    this.elemHelper.ClickJS(driver, By.xpath("//div[@id='code']/button"));
    //NOTE - we have to wait for loading disappear
    this.elemHelper.WaitForElementPresence(driver, By.cssSelector("div.blockUI.blockOverlay"), 5);
    this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay"));
    //Now sample element must be displayed
    assertTrue(this.elemHelper.FindElement(driver, By.id("sample")).isDisplayed());

    /*
     * ## Step 3
     */
    //Pick a date
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("myInput"));
    this.elemHelper.FindElement(driver, By.id("myInput")).sendKeys("''");

    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("ui-datepicker-div"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.className("ui-datepicker-month"));
    this.elemHelper.WaitForElementPresenceAndVisible(driver, By.className("ui-datepicker-year"));
    Select month = new Select(this.elemHelper.FindElement(driver, By.className("ui-datepicker-month")));
    month.selectByValue("9");
    Select year = new Select(this.elemHelper.FindElement(driver, By.className("ui-datepicker-year")));
    year.selectByValue("2011");
    //Day 23
    this.elemHelper.FindElement(driver, By.xpath("//table[@class='ui-datepicker-calendar']//tbody//tr[5]/td/a"))
            .sendKeys(Keys.ENTER);

    String confirmationMsg = this.elemHelper.WaitForAlertReturnConfirmationMsg(driver);

    /*##########################################################################
      EXPECTED RESULT:
      - The popup alert shall displayed the data picked.
     #########################################################################*/
    assertEquals(confirmationMsg, "You chose: 2011-10-23");
}