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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.By;
  20. import org.openqa.selenium.Dimension;
  21. import org.openqa.selenium.WebElement;
  22. import org.openqa.selenium.interactions.Actions;
  23. import com.vaadin.testbench.elements.NotificationElement;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. public class DateFieldTestTest extends MultiBrowserTest {
  26. @Test
  27. public void testMakingRequired() throws InterruptedException {
  28. setDebug(true);
  29. openTestURL();
  30. Thread.sleep(1000);
  31. menu("Component");
  32. menuSub("State");
  33. menu("Required");
  34. assertRequiredIndicatorVisible();
  35. assertNoErrorNotification();
  36. }
  37. private void assertRequiredIndicatorVisible() {
  38. getDriver().findElement(By.className("v-required-field-indicator"));
  39. }
  40. private void assertNoErrorNotification() {
  41. if (isElementPresent(NotificationElement.class)) {
  42. Assert.fail("Notification was present");
  43. }
  44. }
  45. @Test
  46. public void testValueAfterOpeningPopupInRequiredField()
  47. throws InterruptedException {
  48. setDebug(true);
  49. openTestURL();
  50. Thread.sleep(1000);
  51. menu("Component");
  52. menuSub("State");
  53. menu("Required");
  54. assertRequiredIndicatorVisible();
  55. menu("Component");
  56. menuSub("Features");
  57. menuSub("Resolution");
  58. menu("Month");
  59. menu("Component");
  60. menuSub("Listeners");
  61. menu("Value change listener");
  62. String inputtedValue = "2/12";
  63. getInput().sendKeys(inputtedValue);
  64. openPopup();
  65. closePopup();
  66. String actual = getInput().getAttribute("value");
  67. Assert.assertEquals(inputtedValue, actual);
  68. assertNoErrorNotification();
  69. }
  70. private void openPopup() throws InterruptedException {
  71. Dimension size = getInput().getSize();
  72. new Actions(getDriver()).moveToElement(getInput(), 0, 0)
  73. .moveByOffset(size.getWidth() + 5, size.getHeight() / 2)
  74. .click();
  75. // This fails in Opera for some weird reason
  76. // getDriver().findElement(By.className("v-datefield-button")).click();
  77. }
  78. private WebElement getInput() {
  79. return getDriver().findElement(By.xpath("//input"));
  80. }
  81. private void closePopup() {
  82. getDriver().findElement(By.tagName("body")).click();
  83. }
  84. /**
  85. * @since
  86. * @param string
  87. */
  88. private void menuSub(String string) {
  89. getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
  90. .click();
  91. new Actions(getDriver()).moveByOffset(100, 0).build().perform();
  92. }
  93. /**
  94. * @since
  95. * @param string
  96. */
  97. private void menu(String string) {
  98. getDriver().findElement(By.xpath("//span[text() = '" + string + "']"))
  99. .click();
  100. }
  101. }