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.

DateFieldValidationErrorTest.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.vaadin.tests.components.datefield;
  2. import java.time.LocalDate;
  3. import com.vaadin.testbench.elements.DateFieldElement;
  4. import com.vaadin.tests.tb3.MultiBrowserTest;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.Keys;
  8. import org.openqa.selenium.WebElement;
  9. import org.openqa.selenium.support.ui.ExpectedConditions;
  10. public class DateFieldValidationErrorTest extends MultiBrowserTest {
  11. @Test
  12. public void testComponentErrorShouldBeShownWhenEnteringInvalidDate()
  13. throws InterruptedException {
  14. openTestURL();
  15. DateFieldElement dateField = $(DateFieldElement.class).first();
  16. dateField.getInputElement().click();
  17. dateField.getInputElement().sendKeys("01/01/01", Keys.TAB);
  18. assertHasErrorMessage(dateField);
  19. }
  20. @Test
  21. public void testComponentErrorShouldBeShownWhenSelectingInvalidDate()
  22. throws InterruptedException {
  23. openTestURL();
  24. DateFieldElement dateField = $(DateFieldElement.class).first();
  25. dateField.setDate(LocalDate.now());
  26. dateField.openPopup();
  27. waitUntil(ExpectedConditions
  28. .visibilityOfElementLocated(By.className("v-datefield-popup")));
  29. WebElement popup = findElement(
  30. com.vaadin.testbench.By.className("v-datefield-popup"));
  31. // select day before today
  32. WebElement popupBody = popup
  33. .findElement(By.className("v-datefield-calendarpanel"));
  34. popupBody.sendKeys(Keys.ARROW_LEFT, Keys.ENTER);
  35. // move focus away otherwise tooltip is not shown
  36. WebElement inputElement = dateField.getInputElement();
  37. inputElement.click();
  38. inputElement.sendKeys(Keys.TAB);
  39. assertHasErrorMessage(dateField);
  40. }
  41. private void assertHasErrorMessage(DateFieldElement dateField) {
  42. waitForElementPresent(By.className("v-errorindicator"));
  43. dateField.showTooltip();
  44. waitUntil(driver -> "Invalid date"
  45. .equals(getTooltipErrorElement().getText()));
  46. }
  47. @Override
  48. protected boolean requireWindowFocusForIE() {
  49. return true;
  50. }
  51. }