You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DateFieldCloseTest.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package com.vaadin.tests.components.datefield;
  2. import static com.vaadin.tests.components.datefield.DateFieldClose.DATEFIELD_ID;
  3. import static org.junit.Assert.assertFalse;
  4. import static org.junit.Assert.assertTrue;
  5. import org.junit.Test;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8. import com.vaadin.testbench.By;
  9. import com.vaadin.tests.tb3.MultiBrowserTest;
  10. public class DateFieldCloseTest extends MultiBrowserTest {
  11. private WebElement dateField;
  12. @Test
  13. public void closeByClickingCalendarButton() throws Exception {
  14. openTestURL();
  15. dateField = driver.findElement(By.id(DATEFIELD_ID));
  16. clickButton();
  17. checkForCalendarHeader(true);
  18. closePopup();
  19. checkForCalendarHeader(false);
  20. }
  21. private void checkForCalendarHeader(boolean headerShouldExist) {
  22. boolean headerExists = isElementPresent(
  23. By.className("v-datefield-calendarpanel-header"));
  24. if (headerShouldExist) {
  25. assertTrue("The calendar should be visible", headerExists);
  26. } else {
  27. assertFalse("The calendar should not be visible", headerExists);
  28. }
  29. }
  30. private void clickButton() {
  31. WebElement dateFieldButton = dateField
  32. .findElement(By.className("v-datefield-button"));
  33. testBenchElement(dateFieldButton).click(5, 5);
  34. }
  35. private void closePopup() {
  36. WebElement dateFieldButton = dateField
  37. .findElement(By.className("v-datefield-button"));
  38. // To work reliably with IE, need to click and hold instead of just
  39. // clicking the button.
  40. Actions actions = new Actions(driver);
  41. actions.clickAndHold(dateFieldButton).perform();
  42. }
  43. }