aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/test/java/com/vaadin/tests/components/table/CtrlShiftMultiselectTest.java
blob: 2f9a91b7ff7a5eca8726d6228bede4218400ae01 (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
package com.vaadin.tests.components.table;

import java.io.IOException;
import java.util.List;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.vaadin.tests.tb3.MultiBrowserTest;

public class CtrlShiftMultiselectTest extends MultiBrowserTest {

    @Override
    public List<DesiredCapabilities> getBrowsersToTest() {
        return getBrowsersSupportingShiftClick();
    }

    @Override
    protected boolean requireWindowFocusForIE() {
        return true;
    }

    @Test
    public void testSelectionRangeDragging() throws IOException {
        openTestURL();
        clickRow(3);
        new Actions(driver).keyDown(Keys.SHIFT).perform();
        clickRow(8);
        new Actions(driver).keyUp(Keys.SHIFT).perform();
        dragRows(5, 700, 0);
        compareScreen("draggedMultipleRows");
        new Actions(driver).release().perform();
    }

    private void clickRow(int index) {
        List<WebElement> rows = getAllRows();
        rows.get(index).click();
    }

    private void dragRows(int dragIdx, int xOffset, int yOffset) {
        List<WebElement> rows = getAllRows();
        new Actions(driver).moveToElement(rows.get(dragIdx)).clickAndHold()
                .moveByOffset(5, 0).perform();
        new Actions(driver).moveByOffset(xOffset - 5, yOffset).perform();

    }

    private List<WebElement> getAllRows() {
        WebElement table = vaadinElement(
                "/VVerticalLayout[0]/VVerticalLayout[0]/VScrollTable[0]");
        return table.findElements(By.cssSelector(".v-table-table tr"));

    }
}