aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/elements/panel/PanelScrollTest.java
blob: c8267c595fbb49424869a54fa1004382cda83c3e (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
package com.vaadin.tests.elements.panel;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.openqa.selenium.WebElement;

import com.vaadin.testbench.elements.PanelElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

public class PanelScrollTest extends MultiBrowserTest {
    private static final int SCROLL_VALUE = 300;

    @Test
    public void testScrollLeft() throws InterruptedException {
        openTestURL();
        PanelElement panel = $(PanelElement.class).get(0);
        panel.scrollLeft(SCROLL_VALUE);
        assertEquals(SCROLL_VALUE, getScrollLeftValue(panel));
    }

    @Test
    public void testScrollTop() {
        openTestURL();
        PanelElement panel = $(PanelElement.class).get(0);
        panel.scroll(SCROLL_VALUE);
        assertEquals(SCROLL_VALUE, getScrollTopValue(panel));
    }

    // helper functions
    private int getScrollTopValue(WebElement elem) {
        Long scrollTop = (Long) executeScript(
                "return arguments[0].getElementsByClassName(\"v-scrollable\")[0].scrollTop;",
                elem);
        return scrollTop.intValue();
    }

    private int getScrollLeftValue(WebElement elem) {
        Long scrollTop = (Long) executeScript(
                "return arguments[0].getElementsByClassName(\"v-scrollable\")[0].scrollLeft;",
                elem);
        return scrollTop.intValue();
    }
}