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.

DateFieldTestTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.vaadin.tests.components.datefield;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.fail;
  4. import org.junit.Test;
  5. import org.openqa.selenium.By;
  6. import org.openqa.selenium.Dimension;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.interactions.Actions;
  9. import com.vaadin.testbench.elements.NotificationElement;
  10. import com.vaadin.tests.tb3.MultiBrowserTest;
  11. public class DateFieldTestTest extends MultiBrowserTest {
  12. @Test
  13. public void testMakingRequired() throws InterruptedException {
  14. setDebug(true);
  15. openTestURL();
  16. Thread.sleep(1000);
  17. menu("Component");
  18. menuSub("State");
  19. menu("Required");
  20. assertRequiredIndicatorVisible();
  21. assertNoErrorNotification();
  22. }
  23. private void assertRequiredIndicatorVisible() {
  24. getDriver().findElement(By.className("v-required-field-indicator"));
  25. }
  26. private void assertNoErrorNotification() {
  27. if (isElementPresent(NotificationElement.class)) {
  28. fail("Notification was present");
  29. }
  30. }
  31. @Test
  32. public void testValueAfterOpeningPopupInRequiredField()
  33. throws InterruptedException {
  34. setDebug(true);
  35. openTestURL();
  36. Thread.sleep(1000);
  37. menu("Component");
  38. menuSub("State");
  39. menu("Required");
  40. assertRequiredIndicatorVisible();
  41. menu("Component");
  42. menuSub("Features");
  43. menuSub("Resolution");
  44. menu("Month");
  45. menu("Component");
  46. menuSub("Listeners");
  47. menu("Value change listener");
  48. String inputtedValue = "2/12";
  49. getInput().sendKeys(inputtedValue);
  50. openPopup();
  51. closePopup();
  52. String actual = getInput().getAttribute("value");
  53. assertEquals(inputtedValue, actual);
  54. assertNoErrorNotification();
  55. }
  56. private void openPopup() throws InterruptedException {
  57. Dimension size = getInput().getSize();
  58. new Actions(getDriver()).moveToElement(getInput(), 0, 0)
  59. .moveByOffset(size.getWidth() + 5, size.getHeight() / 2)
  60. .click();
  61. // This fails in Opera for some weird reason
  62. // getDriver().findElement(By.className("v-datefield-button")).click();
  63. }
  64. private WebElement getInput() {
  65. return getDriver().findElement(By.xpath("//input"));
  66. }
  67. private void closePopup() {
  68. getDriver().findElement(By.tagName("body")).click();
  69. }
  70. private void menuSub(String string) {
  71. getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
  72. .click();
  73. new Actions(getDriver()).moveByOffset(100, 0).build().perform();
  74. }
  75. private void menu(String string) {
  76. getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
  77. .click();
  78. }
  79. }