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.

DateFieldFaultyInputNotValidTest.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.vaadin.tests.components.datefield;
  2. import static org.junit.Assert.assertEquals;
  3. import java.time.LocalDate;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.interactions.Actions;
  7. import com.vaadin.testbench.elements.ButtonElement;
  8. import com.vaadin.testbench.elements.DateFieldElement;
  9. import com.vaadin.testbench.elements.NotificationElement;
  10. import com.vaadin.tests.tb3.SingleBrowserTest;
  11. public class DateFieldFaultyInputNotValidTest extends SingleBrowserTest {
  12. @Test
  13. public void testEmptyDateFieldOK() {
  14. openTestURL();
  15. $(ButtonElement.class).first().click();
  16. assertEquals("Empty DateField should be ok", "OK",
  17. $(NotificationElement.class).first().getText());
  18. }
  19. @Test
  20. public void testFaultyUserInput() {
  21. openTestURL();
  22. DateFieldElement dateField = $(DateFieldElement.class).first();
  23. dateField.setDate(LocalDate.now());
  24. $(ButtonElement.class).first().click();
  25. assertEquals("Current date should be ok", "OK",
  26. $(NotificationElement.class).first().getText());
  27. $(NotificationElement.class).first().close();
  28. dateField.findElement(By.tagName("input")).click();
  29. new Actions(getDriver()).sendKeys("asd").perform();
  30. $(ButtonElement.class).first().click();
  31. assertEquals("Added 'asd' should make date not parse correctly.",
  32. "Fail", $(NotificationElement.class).first().getText());
  33. }
  34. @Test
  35. public void testDateOutOfRange() {
  36. openTestURL();
  37. DateFieldElement dateField = $(DateFieldElement.class).first();
  38. dateField.setDate(LocalDate.now());
  39. $(ButtonElement.class).first().click();
  40. assertEquals("Current date should be ok", "OK",
  41. $(NotificationElement.class).first().getText());
  42. $(NotificationElement.class).first().close();
  43. dateField.setDate(LocalDate.now().minusDays(7));
  44. $(ButtonElement.class).first().click();
  45. assertEquals("Last week should not be ok", "Fail",
  46. $(NotificationElement.class).first().getText());
  47. }
  48. @Test
  49. public void testParseErrorClearedOnValidInput() {
  50. testFaultyUserInput();
  51. $(NotificationElement.class).first().close();
  52. $(DateFieldElement.class).first().setDate(LocalDate.now());
  53. $(ButtonElement.class).first().click();
  54. assertEquals("Current date should be ok", "OK",
  55. $(NotificationElement.class).first().getText());
  56. }
  57. }