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.

ReloadWidgetsTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.vaadin.tests.components.table;
  2. import static org.junit.Assert.assertTrue;
  3. import java.util.List;
  4. import org.junit.Test;
  5. import org.openqa.selenium.WebDriver;
  6. import org.openqa.selenium.WebElement;
  7. import org.openqa.selenium.support.ui.ExpectedCondition;
  8. import com.vaadin.testbench.By;
  9. import com.vaadin.testbench.elements.TableElement;
  10. import com.vaadin.tests.tb3.MultiBrowserTest;
  11. public class ReloadWidgetsTest extends MultiBrowserTest {
  12. private int rowHeight = -1;
  13. private WebElement wrapper;
  14. @Override
  15. public void setup() throws Exception {
  16. super.setup();
  17. openTestURL();
  18. TableElement table = $(TableElement.class).id("table");
  19. rowHeight = table.getCell(1, 0).getLocation().getY()
  20. - table.getCell(0, 0).getLocation().getY();
  21. wrapper = findElement(By.className("v-table-body-wrapper"));
  22. }
  23. @Test
  24. public void testScrollingThenUpdatingContents() throws Exception {
  25. // Scroll down to row 44 so that we get the cut-off point where the
  26. // problem becomes apparent
  27. testBenchElement(wrapper).scroll(44 * rowHeight);
  28. waitForScrollToFinish();
  29. // Assert that we have the button widget.
  30. assertTrue(
  31. "Button widget was not found after scrolling for the first time",
  32. !findElements(By.id("46")).isEmpty());
  33. // Now refresh the container contents
  34. WebElement refreshButton = findElement(By.id("refresh"));
  35. refreshButton.click();
  36. // Again scroll down to row 44 so we get the cut-off point visible
  37. testBenchElement(wrapper).scroll(44 * rowHeight);
  38. waitForScrollToFinish();
  39. // Assert that we still get the button
  40. assertTrue(
  41. "Button widget was not found after refreshing container items.",
  42. !findElements(By.id("46")).isEmpty());
  43. }
  44. /**
  45. * Waits until the scroll position indicator goes away, signifying that all
  46. * the required rows have been fetched.
  47. */
  48. private void waitForScrollToFinish() {
  49. waitUntil(new ExpectedCondition<Boolean>() {
  50. @Override
  51. public Boolean apply(WebDriver input) {
  52. List<WebElement> elements = findElements(
  53. By.className("v-table-scrollposition"));
  54. return elements.isEmpty() || !elements.get(0).isDisplayed();
  55. }
  56. @Override
  57. public String toString() {
  58. // Timed out after 10 seconds waiting for ...
  59. return "scroll position indicator to vanish";
  60. }
  61. });
  62. }
  63. }