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.

DateFieldIsValidTest.java 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.vaadin.tests.components.datefield;
  2. import static org.junit.Assert.assertTrue;
  3. import org.junit.Test;
  4. import org.openqa.selenium.Keys;
  5. import org.openqa.selenium.WebElement;
  6. import com.vaadin.testbench.By;
  7. import com.vaadin.testbench.elements.AbstractDateFieldElement;
  8. import com.vaadin.testbench.elements.ButtonElement;
  9. import com.vaadin.tests.tb3.MultiBrowserTest;
  10. /**
  11. * @author Vaadin Ltd
  12. */
  13. public class DateFieldIsValidTest extends MultiBrowserTest {
  14. @Test
  15. public void testInvalidText() throws Exception {
  16. openTestURL();
  17. waitForElementVisible(By.id("Log"));
  18. waitForElementVisible(By.className("v-datefield"));
  19. WebElement dateTextbox = $(AbstractDateFieldElement.class).first()
  20. .findElement(By.className("v-textfield"));
  21. ButtonElement button = $(ButtonElement.class).first();
  22. dateTextbox.sendKeys("01/01/01", Keys.TAB);
  23. assertLogText("1. valueChange: value: 01/01/01, is valid: true");
  24. button.click();
  25. assertLogText("2. buttonClick: value: 01/01/01, is valid: true");
  26. dateTextbox.sendKeys("lala", Keys.TAB);
  27. assertLogText("3. valueChange: value: null, is valid: false");
  28. button.click();
  29. assertLogText("4. buttonClick: value: null, is valid: false");
  30. dateTextbox.clear();
  31. button.click();
  32. assertLogText("5. buttonClick: value: null, is valid: true");
  33. dateTextbox.sendKeys("02/02/02", Keys.TAB);
  34. assertLogText("6. valueChange: value: 02/02/02, is valid: true");
  35. button.click();
  36. assertLogText("7. buttonClick: value: 02/02/02, is valid: true");
  37. }
  38. private void assertLogText(String expected) throws Exception {
  39. String text = findElement(By.vaadin("PID_SLog_row_0")).getText();
  40. assertTrue("Expected '" + expected + "' found '" + text + "'",
  41. text.equals(expected));
  42. }
  43. }