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.7KB

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