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
|
package com.vaadin.tests.components.table;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import com.vaadin.testbench.elements.TableElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
/**
* Tests clicks on different types of Table contents.
*
* @author Vaadin Ltd
*/
public class LabelEmbeddedClickThroughForTableTest extends MultiBrowserTest {
@Test
public void testNotification() {
openTestURL();
TableElement table = $(TableElement.class).first();
// click first cell of first row
clickCell(table, 0, 0);
// click first cell of second row
clickCell(table, 1, 0);
// click the ordinary label component on first row
clickLabel(table, 0, 1);
// click the ordinary label component on second row
clickLabel(table, 1, 1);
// click the html-content label component on first row
clickBoldTag(table, 0, 2);
// click the ordinary label component on second row (some browsers
// navigate away from the page if you try to click the link in the
// html-content label)
clickLabel(table, 1, 1);
// click the embedded image on first row
clickImageTag(table, 0, 3);
// click the embedded image on second row
clickImageTag(table, 1, 3);
}
private void clickImageTag(TableElement table, int row, int column) {
table.getCell(row, column).findElement(By.className("v-embedded"))
.findElement(By.tagName("img")).click();
checkRowSelected(table, row);
}
private void clickBoldTag(TableElement table, int row, int column) {
table.getCell(row, column).findElement(By.className("v-label"))
.findElement(By.tagName("b")).click();
checkRowSelected(table, row);
}
private void clickLabel(TableElement table, int row, int column) {
table.getCell(row, column).findElement(By.className("v-label")).click();
checkRowSelected(table, row);
}
private void clickCell(TableElement table, int row, int column) {
table.getCell(row, column).click();
checkRowSelected(table, row);
}
private void checkRowSelected(TableElement table, int rowIndex) {
List<WebElement> selectedRows = table
.findElement(By.className("v-table-body"))
.findElements(By.className("v-selected"));
assertEquals("unexpected table selection size", 1, selectedRows.size());
assertEquals(
"contents of the selected row don't match contents of the row #"
+ rowIndex,
table.getCell(rowIndex, 0).getText(),
selectedRows.get(0)
.findElement(By.className("v-table-cell-wrapper"))
.getText());
}
}
|