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.

DateFieldPopupClosingTest.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package com.vaadin.tests.components.datefield;
  2. import java.io.IOException;
  3. import org.junit.Test;
  4. import org.openqa.selenium.By;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.interactions.Actions;
  8. import org.openqa.selenium.support.ui.ExpectedCondition;
  9. import org.openqa.selenium.support.ui.ExpectedConditions;
  10. import com.vaadin.testbench.elements.AbstractDateFieldElement;
  11. import com.vaadin.tests.tb3.MultiBrowserTest;
  12. public class DateFieldPopupClosingTest extends MultiBrowserTest {
  13. @Test
  14. public void testDateFieldPopupClosingLongClick()
  15. throws InterruptedException, IOException {
  16. openTestURL();
  17. fastClickDateDatePickerButton();
  18. assertThatPopupIsVisible();
  19. longClickDateDatePickerButton();
  20. assertThatPopupIsInvisible();
  21. }
  22. private void assertThatPopupIsVisible() {
  23. waitUntil(ExpectedConditions
  24. .visibilityOfElementLocated(By.className("v-datefield-popup")));
  25. }
  26. private void assertThatPopupIsInvisible() {
  27. // ExpectedConditions.invisibilityOfElementLocated doesn't work
  28. // with PhantomJS when running with a hub:
  29. // https://code.google.com/p/selenium/issues/detail?id=5000
  30. // so we need to make our own.
  31. waitUntil(new ExpectedCondition<Boolean>() {
  32. @Override
  33. public Boolean apply(WebDriver input) {
  34. try {
  35. return !(findElement(By.className("v-datefield-popup"))
  36. .isDisplayed());
  37. } catch (Exception e) {
  38. return true;
  39. }
  40. }
  41. @Override
  42. public String toString() {
  43. // Timed out after 10 seconds waiting for ...
  44. return "popup to not be visible";
  45. }
  46. });
  47. }
  48. private void longClickDateDatePickerButton() {
  49. WebElement button = getToggleButton();
  50. new Actions(getDriver()).clickAndHold(button).perform();
  51. assertThatPopupIsInvisible();
  52. new Actions(getDriver()).release(button).perform();
  53. }
  54. private WebElement getToggleButton() {
  55. AbstractDateFieldElement dateField = $(AbstractDateFieldElement.class)
  56. .first();
  57. return dateField.findElement(By.tagName("button"));
  58. }
  59. private void fastClickDateDatePickerButton() {
  60. getToggleButton().click();
  61. }
  62. }