Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

DateTimeFieldIsValidTest.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.datefield;
  17. import org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.Keys;
  20. import org.openqa.selenium.WebElement;
  21. import com.vaadin.testbench.By;
  22. import com.vaadin.testbench.customelements.AbstractDateFieldElement;
  23. import com.vaadin.testbench.elements.ButtonElement;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. /**
  26. * @author Vaadin Ltd
  27. */
  28. public class DateTimeFieldIsValidTest extends MultiBrowserTest {
  29. @Test
  30. public void testInvalidText() throws Exception {
  31. openTestURL();
  32. waitForElementVisible(By.id("Log"));
  33. waitForElementVisible(By.className("v-datefield"));
  34. WebElement dateTextbox = $(AbstractDateFieldElement.class).first()
  35. .findElement(By.className("v-textfield"));
  36. ButtonElement button = $(ButtonElement.class).first();
  37. dateTextbox.sendKeys("01/01/01 1.12", Keys.TAB);
  38. assertLogText("1. valueChange: value: 01/01/01 1.12, is valid: true");
  39. button.click();
  40. assertLogText("2. buttonClick: value: 01/01/01 1.12, is valid: true");
  41. dateTextbox.sendKeys("lala", Keys.TAB);
  42. assertLogText("3. valueChange: value: null, is valid: false");
  43. button.click();
  44. assertLogText("4. buttonClick: value: null, is valid: false");
  45. dateTextbox.clear();
  46. dateTextbox.sendKeys("02/02/02 2.34", Keys.TAB);
  47. assertLogText("5. valueChange: value: 02/02/02 2.34, is valid: true");
  48. button.click();
  49. assertLogText("6. buttonClick: value: 02/02/02 2.34, is valid: true");
  50. }
  51. private void assertLogText(String expected) throws Exception {
  52. String text = findElement(By.vaadin("PID_SLog_row_0")).getText();
  53. Assert.assertTrue("Expected '" + expected + "' found '" + text + "'",
  54. text.equals(expected));
  55. }
  56. }