1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.wysiwyg.framework; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import org.apache.commons.lang3.StringUtils; |
25 |
|
import org.openqa.selenium.By; |
26 |
|
import org.openqa.selenium.Keys; |
27 |
|
import org.openqa.selenium.WebDriver; |
28 |
|
import org.openqa.selenium.WebElement; |
29 |
|
import org.openqa.selenium.interactions.Actions; |
30 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
31 |
|
import org.xwiki.test.ui.XWikiWebDriver; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
|
|
|
| 81.3% |
Uncovered Elements: 17 (91) |
Complexity: 36 |
Complexity Density: 0.65 |
|
38 |
|
public class XWikiExplorer |
39 |
|
{ |
40 |
|
private static final String FINDER_LOCATOR = |
41 |
|
"//input[@class = 'xtree-finder' and following-sibling::div[contains(@class, 'xExplorer')]]"; |
42 |
|
|
43 |
|
private static final By SELECTED_NODE = By |
44 |
|
.xpath("//div[contains(@class, 'xExplorer')]//li[@role = 'treeitem' and @aria-selected = 'true']"); |
45 |
|
|
46 |
|
private final XWikiWebDriver driver; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@param |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
71 |
public XWikiExplorer(XWikiWebDriver driver)... |
54 |
|
{ |
55 |
71 |
this.driver = driver; |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@param |
62 |
|
@return |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
public XWikiExplorer openSpace(String spaceName)... |
65 |
|
{ |
66 |
0 |
return open(getSpaceNodeId(spaceName)); |
67 |
|
} |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
@param |
73 |
|
@param |
74 |
|
@return |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
1 |
public XWikiExplorer openPage(String spaceName, String pageName)... |
77 |
|
{ |
78 |
1 |
return open(getDocumentNodeId(spaceName, pageName)); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@param |
85 |
|
@param |
86 |
|
@return |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
1 |
public XWikiExplorer openAttachments(String spaceName, String pageName)... |
89 |
|
{ |
90 |
1 |
return open(getAttachmentsNodeId(spaceName, pageName)); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
93 |
2 |
private XWikiExplorer open(String nodeId)... |
94 |
|
{ |
95 |
|
|
96 |
|
|
97 |
2 |
select(nodeId); |
98 |
|
|
99 |
2 |
String toggleLocatorFormat = |
100 |
|
"//div[contains(@class, 'xExplorer')]//li[@id = '%s'" |
101 |
|
+ " and @aria-expanded = '%s']/i[contains(@class, 'jstree-ocl')]"; |
102 |
2 |
this.driver.findElementByXPath(String.format(toggleLocatorFormat, nodeId, false)).click(); |
103 |
2 |
this.driver.waitUntilElementIsVisible(By.xpath(String.format(toggleLocatorFormat, nodeId, true))); |
104 |
|
|
105 |
2 |
return this; |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
@return |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
public XWikiExplorer selectSpace(String spaceName)... |
115 |
|
{ |
116 |
0 |
return select(getSpaceNodeId(spaceName)); |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
@param |
123 |
|
@return |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
125 |
2 |
public XWikiExplorer selectNewPage(String spaceName)... |
126 |
|
{ |
127 |
2 |
return select(getNewDocumentNodeId(spaceName)); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
@param |
135 |
|
@return |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
public XWikiExplorer selectPage(String spaceName, String pageName)... |
138 |
|
{ |
139 |
0 |
return select(getDocumentNodeId(spaceName, pageName)); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
@param |
148 |
|
@return |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
2 |
public XWikiExplorer togglePageSelection(String spaceName, String pageName)... |
151 |
|
{ |
152 |
2 |
return toggleSelection(getDocumentNodeId(spaceName, pageName)); |
153 |
|
} |
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
@param |
160 |
|
@return |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
1 |
public XWikiExplorer selectNewAttachment(String spaceName, String pageName)... |
163 |
|
{ |
164 |
1 |
return select(String.format("addAttachment:xwiki:%s.%s", spaceName, pageName)); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
@param |
172 |
|
@param |
173 |
|
@return |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
175 |
1 |
public XWikiExplorer selectAttachment(String spaceName, String pageName, String fileName)... |
176 |
|
{ |
177 |
1 |
return select(getAttachmentNodeId(spaceName, pageName, fileName)); |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
180 |
6 |
private XWikiExplorer select(String nodeId)... |
181 |
|
{ |
182 |
6 |
this.driver.findElementByXPath(getNodeLocator(nodeId) + "/a[@class = 'jstree-anchor']").click(); |
183 |
6 |
return this; |
184 |
|
} |
185 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
186 |
2 |
private XWikiExplorer toggleSelection(String nodeId)... |
187 |
|
{ |
188 |
2 |
WebElement node = |
189 |
|
this.driver.findElementByXPath(getNodeLocator(nodeId) + "/a[contains(@class, 'jstree-anchor')]"); |
190 |
2 |
new Actions(this.driver).keyDown(Keys.CONTROL).click(node).keyUp(Keys.CONTROL).perform(); |
191 |
2 |
return this; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
@param |
196 |
|
@return |
197 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
0 |
public boolean hasSpace(String spaceName)... |
199 |
|
{ |
200 |
0 |
return hasNode(getSpaceNodeId(spaceName)); |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
@param |
206 |
|
@return |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
4 |
public boolean hasPage(String spaceName, String pageName)... |
209 |
|
{ |
210 |
4 |
return hasNode(getDocumentNodeId(spaceName, pageName)); |
211 |
|
} |
212 |
|
|
213 |
|
|
214 |
|
@param |
215 |
|
@param |
216 |
|
@param |
217 |
|
@return |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
0 |
public boolean hasAttachment(String spaceName, String pageName, String fileName)... |
220 |
|
{ |
221 |
0 |
return hasNode(getAttachmentNodeId(spaceName, pageName, fileName)); |
222 |
|
} |
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
4 |
private boolean hasNode(String nodeId)... |
225 |
|
{ |
226 |
4 |
return this.driver.hasElementWithoutWaiting(By.xpath(getNodeLocator(nodeId))); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
@param |
233 |
|
@return |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
235 |
0 |
public XWikiExplorer findAndSelectSpace(String spaceName)... |
236 |
|
{ |
237 |
0 |
find(spaceName).selectSpace(spaceName); |
238 |
0 |
return waitForNodeSelected(); |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
@return |
246 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
247 |
16 |
public XWikiExplorer findAndSelectPage(String pageTitle)... |
248 |
|
{ |
249 |
16 |
find(pageTitle).selectPage(pageTitle); |
250 |
16 |
return waitForNodeSelected(); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
@param |
257 |
|
@return |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
259 |
5 |
public XWikiExplorer findAndSelectAttachment(String fileName)... |
260 |
|
{ |
261 |
5 |
find(fileName).selectAttachment(fileName); |
262 |
5 |
return waitForNodeSelected(); |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
@param |
269 |
|
@return |
270 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
271 |
26 |
public TreeSuggestionsPane find(String text)... |
272 |
|
{ |
273 |
26 |
WebElement finder = this.driver.findElementByXPath(FINDER_LOCATOR); |
274 |
26 |
finder.clear(); |
275 |
26 |
finder.sendKeys(text); |
276 |
|
|
277 |
26 |
this.driver.waitUntilElementIsVisible(By |
278 |
|
.xpath("//div[contains(@class, 'xtree-finder-suggestions')]//ul[contains(@class, 'suggestList')]")); |
279 |
26 |
return new TreeSuggestionsPane(this.driver); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
@return |
286 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
287 |
12 |
public XWikiExplorer waitForIt()... |
288 |
|
{ |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
12 |
this.driver.waitUntilCondition(new ExpectedCondition<Boolean>() |
293 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
294 |
18 |
@Override... |
295 |
|
public Boolean apply(WebDriver input) |
296 |
|
{ |
297 |
18 |
List<WebElement> finders = |
298 |
|
XWikiExplorer.this.driver.findElementsWithoutWaiting(By.xpath(FINDER_LOCATOR)); |
299 |
18 |
return (!finders.isEmpty() && !StringUtils.isEmpty(finders.get(0).getAttribute("value"))) |
300 |
|
|| XWikiExplorer.this.driver.hasElementWithoutWaiting(SELECTED_NODE); |
301 |
|
} |
302 |
|
}); |
303 |
12 |
return this; |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
@param |
310 |
|
@param |
311 |
|
@return |
312 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
313 |
16 |
public XWikiExplorer waitForPageSelected(String spaceName, String pageName)... |
314 |
|
{ |
315 |
16 |
return waitForNodeSelected(getDocumentNodeId(spaceName, pageName)); |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
@param |
322 |
|
@return |
323 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
324 |
0 |
public XWikiExplorer waitForNewPageSelected(String spaceName)... |
325 |
|
{ |
326 |
0 |
return waitForNodeSelected(getNewDocumentNodeId(spaceName)); |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
@param |
333 |
|
@param |
334 |
|
@param |
335 |
|
@return |
336 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
337 |
5 |
public XWikiExplorer waitForAttachmentSelected(String spaceName, String pageName, String fileName)... |
338 |
|
{ |
339 |
5 |
return waitForNodeSelected(getAttachmentNodeId(spaceName, pageName, fileName)); |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
@param |
347 |
|
@param |
348 |
|
@return |
349 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
350 |
2 |
public XWikiExplorer waitForAttachmentsSelected(String spaceName, String pageName)... |
351 |
|
{ |
352 |
2 |
return waitForNodeSelected(getAttachmentsNodeId(spaceName, pageName)); |
353 |
|
} |
354 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
355 |
21 |
private XWikiExplorer waitForNodeSelected()... |
356 |
|
{ |
357 |
21 |
this.driver.waitUntilElementIsVisible(SELECTED_NODE); |
358 |
21 |
return this; |
359 |
|
} |
360 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
361 |
23 |
private XWikiExplorer waitForNodeSelected(String nodeId)... |
362 |
|
{ |
363 |
23 |
this.driver.waitUntilElementIsVisible(By.xpath(String.format( |
364 |
|
"//div[contains(@class, 'xExplorer')]//li[@id = '%s' and @aria-selected = 'true']", nodeId))); |
365 |
23 |
return this; |
366 |
|
} |
367 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
368 |
1 |
public XWikiExplorer waitForFinderValue(final String value)... |
369 |
|
{ |
370 |
1 |
this.driver.waitUntilElementHasAttributeValue(By.xpath(FINDER_LOCATOR), "value", value); |
371 |
1 |
return this; |
372 |
|
} |
373 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
374 |
23 |
private String getDocumentNodeId(String spaceName, String pageName)... |
375 |
|
{ |
376 |
23 |
return String.format("document:xwiki:%s.%s", spaceName, pageName); |
377 |
|
} |
378 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
379 |
2 |
private String getNewDocumentNodeId(String spaceName)... |
380 |
|
{ |
381 |
2 |
return String.format("addDocument:xwiki:%s.WebHome", spaceName); |
382 |
|
} |
383 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
384 |
0 |
private String getSpaceNodeId(String spaceName)... |
385 |
|
{ |
386 |
0 |
return "space:xwiki:" + spaceName; |
387 |
|
} |
388 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
6 |
private String getAttachmentNodeId(String spaceName, String pageName, String fileName)... |
390 |
|
{ |
391 |
6 |
return String.format("attachment:xwiki:%s.%s@%s", spaceName, pageName, fileName); |
392 |
|
} |
393 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
394 |
3 |
private String getAttachmentsNodeId(String spaceName, String pageName)... |
395 |
|
{ |
396 |
3 |
return String.format("attachments:xwiki:%s.%s", spaceName, pageName); |
397 |
|
} |
398 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
399 |
12 |
private String getNodeLocator(String nodeId)... |
400 |
|
{ |
401 |
12 |
return String.format("//div[contains(@class, 'xExplorer')]//li[@id = '%s']", nodeId); |
402 |
|
} |
403 |
|
} |