aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/table/ReloadWidgetsTest.java
blob: 49e356e3cedf997ff00bccbcd55a2da600676c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.vaadin.tests.components.table;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;

import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class ReloadWidgetsTest extends MultiBrowserTest {

    private int rowHeight = -1;

    private WebElement wrapper;

    @Override
    public void setup() throws Exception {
        super.setup();
        openTestURL();

        TableElement table = $(TableElement.class).id("table");
        rowHeight = table.getCell(1, 0).getLocation().getY()
                - table.getCell(0, 0).getLocation().getY();

        wrapper = findElement(By.className("v-table-body-wrapper"));
    }

    @Test
    public void testScrollingThenUpdatingContents() throws Exception {
        // Scroll down to row 44 so that we get the cut-off point where the
        // problem becomes apparent
        testBenchElement(wrapper).scroll(44 * rowHeight);
        waitForScrollToFinish();

        // Assert that we have the button widget.
        assertTrue(
                "Button widget was not found after scrolling for the first time",
                !findElements(By.id("46")).isEmpty());

        // Now refresh the container contents
        WebElement refreshButton = findElement(By.id("refresh"));
        refreshButton.click();

        // Again scroll down to row 44 so we get the cut-off point visible
        testBenchElement(wrapper).scroll(44 * rowHeight);
        waitForScrollToFinish();

        // Assert that we still get the button
        assertTrue(
                "Button widget was not found after refreshing container items.",
                !findElements(By.id("46")).isEmpty());
    }

    /**
     * Waits until the scroll position indicator goes away, signifying that all
     * the required rows have been fetched.
     */
    private void waitForScrollToFinish() {
        waitUntil(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver input) {
                List<WebElement> elements = findElements(
                        By.className("v-table-scrollposition"));
                return elements.isEmpty() || !elements.get(0).isDisplayed();
            }

            @Override
            public String toString() {
                // Timed out after 10 seconds waiting for ...
                return "scroll position indicator to vanish";
            }
        });
    }

}