1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.ui.po; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import org.openqa.selenium.By; |
25 |
|
import org.openqa.selenium.WebElement; |
26 |
|
import org.openqa.selenium.WebDriverException; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@version |
32 |
|
@since |
33 |
|
|
|
|
| 49.4% |
Uncovered Elements: 40 (79) |
Complexity: 26 |
Complexity Density: 0.6 |
|
34 |
|
public class TableElement extends BaseElement |
35 |
|
{ |
36 |
|
private final WebElement table; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
private int empty = -1; |
41 |
|
|
42 |
|
private int numberOfColumns = -1; |
43 |
|
|
44 |
|
private int numberOfRows = -1; |
45 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
46 |
10 |
public TableElement(WebElement table)... |
47 |
|
{ |
48 |
10 |
super(); |
49 |
10 |
if (!table.getTagName().toLowerCase().equals("table")) { |
50 |
0 |
throw new WebDriverException("You can only create a TableElement using a <table> web element," |
51 |
|
+ "you passed a <" + table.getTagName() + "> element"); |
52 |
|
} |
53 |
10 |
if (!table.findElements(By.tagName("tbody")).isEmpty()) { |
54 |
10 |
this.table = table.findElements(By.tagName("tbody")).get(0); |
55 |
|
} else { |
56 |
0 |
this.table = table; |
57 |
|
} |
58 |
|
} |
59 |
|
|
60 |
|
@return |
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
61 |
0 |
public boolean isEmpty()... |
62 |
|
{ |
63 |
0 |
if (empty == -1) { |
64 |
0 |
for (WebElement row : table.findElements(By.tagName("tr"))) { |
65 |
0 |
if (!row.findElements(By.tagName("td")).isEmpty()) { |
66 |
0 |
empty = 0; |
67 |
0 |
return false; |
68 |
|
} |
69 |
|
} |
70 |
0 |
empty = 1; |
71 |
|
} |
72 |
0 |
return (empty == 1); |
73 |
|
} |
74 |
|
|
75 |
|
@return |
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
76 |
9 |
public int numberOfColumns()... |
77 |
|
{ |
78 |
9 |
if (numberOfRows() == 0) { |
79 |
0 |
return 0; |
80 |
|
} |
81 |
9 |
if (numberOfColumns == -1) { |
82 |
9 |
numberOfColumns = getRow(0).size(); |
83 |
|
} |
84 |
9 |
return numberOfColumns; |
85 |
|
} |
86 |
|
|
87 |
|
@return |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
88 |
48 |
public int numberOfRows()... |
89 |
|
{ |
90 |
48 |
if (numberOfRows == -1) { |
91 |
10 |
numberOfRows = table.findElements(By.tagName("tr")).size(); |
92 |
|
} |
93 |
48 |
return numberOfRows; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
@param |
98 |
|
@return |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
7 |
public List<WebElement> getColumn(String firstEntry)... |
101 |
|
{ |
102 |
7 |
return getColumn(getColumnNumber(firstEntry)); |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
@return |
108 |
|
|
|
|
| 72.7% |
Uncovered Elements: 3 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
109 |
7 |
public int getColumnNumber(String firstEntry)... |
110 |
|
{ |
111 |
7 |
if (numberOfRows() == 0) { |
112 |
0 |
return -1; |
113 |
|
} |
114 |
7 |
List<WebElement> headers = getRow(0); |
115 |
7 |
for (WebElement header : headers) { |
116 |
24 |
if (header.getText().equals(firstEntry)) { |
117 |
7 |
return headers.indexOf(header); |
118 |
|
} |
119 |
|
} |
120 |
0 |
return -1; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
@param |
125 |
|
@return |
126 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
127 |
7 |
public List<WebElement> getColumn(int columnNumber)... |
128 |
|
{ |
129 |
7 |
if (numberOfRows() == 0 || numberOfColumns() < columnNumber || columnNumber < 0) { |
130 |
0 |
return null; |
131 |
|
} |
132 |
|
|
133 |
7 |
return table.findElements(By.xpath("//tr/th[" + (columnNumber + 1) + "]" |
134 |
|
+ " | //tr/td[" + (columnNumber + 1) + "]")); |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
@param |
139 |
|
|
140 |
|
@return |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
0 |
public List<WebElement> getRow(String firstEntry)... |
143 |
|
{ |
144 |
0 |
return getRow(getRowNumber(firstEntry)); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
@param |
149 |
|
|
150 |
|
@return |
151 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
152 |
0 |
public int getRowNumber(String firstEntry)... |
153 |
|
{ |
154 |
0 |
if (numberOfColumns() == 0) { |
155 |
0 |
return -1; |
156 |
|
} |
157 |
0 |
List<WebElement> headers = getColumn(0); |
158 |
0 |
for (WebElement header : headers) { |
159 |
0 |
if (header.getText().equals(firstEntry)) { |
160 |
0 |
return headers.indexOf(header); |
161 |
|
} |
162 |
|
} |
163 |
0 |
return -1; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
@param |
168 |
|
@return |
169 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
170 |
23 |
public List<WebElement> getRow(int rowNumber)... |
171 |
|
{ |
172 |
23 |
if (numberOfRows() <= rowNumber || rowNumber < 0) { |
173 |
0 |
return null; |
174 |
|
} |
175 |
23 |
return table.findElements(By.xpath("//tr[" + (rowNumber + 1) + "]/th" |
176 |
|
+ " | //tr[" + (rowNumber + 1) + "]/td")); |
177 |
|
} |
178 |
|
} |