aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/combobox/ComboBoxScrollingWithArrowsTest.java
blob: 284cead06b5db0f42e3c223989a9b70d6d19800f (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
82
83
package com.vaadin.tests.components.combobox;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

import java.util.List;

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

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

/**
 * When pressed down key, while positioned on the last item - should show next
 * page and focus on the first item of the next page.
 */
public class ComboBoxScrollingWithArrowsTest extends MultiBrowserTest {

    private final int PAGESIZE = 10;

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

        openTestURL();
        openPopup();
    }

    private WebElement getDropDown() {
        // Selenium is used instead of TestBench4, because there is no method to
        // access the popup of the combobox
        // The method ComboBoxElement.openPopup() opens the popup, but doesn't
        // provide any way to access the popup and send keys to it.
        // Ticket #13756

        return driver.findElement(By.className("v-filterselect-input"));
    }

    private void openPopup() {
        ComboBoxElement cb = $(ComboBoxElement.class).first();
        cb.openPopup();
    }

    @Test
    public void scrollDownArrowKeyTest() throws InterruptedException {
        WebElement dropDownComboBox = getDropDown();

        for (int i = 0; i < PAGESIZE; i++) {
            dropDownComboBox.sendKeys(Keys.DOWN);
        }

        assertThat(getSelectedItemText(), is("item " + PAGESIZE)); // item 10
    }

    private String getSelectedItemText() {
        List<WebElement> items = driver
                .findElements(By.className("gwt-MenuItem-selected"));
        return items.get(0).getText();
    }

    @Test
    public void scrollUpArrowKeyTest() throws InterruptedException {
        WebElement dropDownComboBox = getDropDown();

        for (int i = 0; i < PAGESIZE; i++) {
            dropDownComboBox.sendKeys(Keys.DOWN);
        }

        // move to one item up
        waitUntilNextPageIsVisible();
        dropDownComboBox.sendKeys(Keys.UP);

        // item 9
        assertThat(getSelectedItemText(), is("item " + (PAGESIZE - 1)));
    }

    private void waitUntilNextPageIsVisible() {
        waitUntil(input -> getSelectedItemText().equals("item " + PAGESIZE), 5);
    }
}