blob: f18042ee5cd36b5887191f900ff538323a86a621 (
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
84
85
86
87
88
89
90
91
92
93
94
|
package com.vaadin.tests.components.table;
import static com.vaadin.tests.components.table.SelectAllRows.TOTAL_NUMBER_OF_ROWS;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
/**
* Test to see if all items of the table can be selected by selecting first row,
* press shift then select last (#13008)
*
* @author Vaadin Ltd
*/
public class SelectAllRowsTest extends MultiBrowserTest {
@Override
protected boolean requireWindowFocusForIE() {
return true;
}
@Override
public List<DesiredCapabilities> getBrowsersToTest() {
return getBrowsersSupportingShiftClick();
}
@Test
public void testAllRowsAreSelected() {
openTestURL();
clickFirstRow();
scrollTableToBottom();
clickLastRow();
assertEquals(TOTAL_NUMBER_OF_ROWS, countSelectedItems());
}
protected void clickFirstRow() {
getVisibleTableRows().get(0).click();
}
private void clickLastRow() {
List<WebElement> rows = getVisibleTableRows();
shiftClickElement(rows.get(rows.size() - 1));
}
protected void shiftClickElement(WebElement element) {
new Actions(getDriver()).keyDown(Keys.SHIFT).click(element)
.keyUp(Keys.SHIFT).perform();
}
private int countSelectedItems() {
$(ButtonElement.class).first().click();
String count = $(LabelElement.class).get(1).getText();
return Integer.parseInt(count);
}
private TableElement getTable() {
return $(TableElement.class).first();
}
private void scrollTableToBottom() {
testBenchElement(getTable().findElement(By.className("v-scrollable")))
.scroll(TOTAL_NUMBER_OF_ROWS * 30);
waitUntilRowIsVisible(TOTAL_NUMBER_OF_ROWS - 1);
}
private void waitUntilRowIsVisible(final int row) {
waitUntil(input -> {
try {
return getTable().getCell(row, 0) != null;
} catch (NoSuchElementException e) {
return false;
}
});
}
protected List<WebElement> getVisibleTableRows() {
return getTable().findElements(By.cssSelector(".v-table-table tr"));
}
}
|