1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.test.po; |
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.WebElement; |
27 |
|
import org.xwiki.extension.ExtensionId; |
28 |
|
import org.xwiki.test.ui.po.BaseElement; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 86.6% |
Uncovered Elements: 16 (119) |
Complexity: 43 |
Complexity Density: 0.66 |
|
36 |
|
public class ExtensionPane extends BaseElement |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
private static final String ACTION_BUTTON_XPATH = |
42 |
|
".//button[@name = 'extensionAction' and @value='%s' and normalize-space(text())='%s']"; |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
private static final String CLASS_ATTRIBUTE = "class"; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private final WebElement container; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
61 |
public ExtensionPane(WebElement container)... |
60 |
|
{ |
61 |
61 |
this.container = container; |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
@return |
66 |
|
|
67 |
|
|
|
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
68 |
16 |
public String getStatus()... |
69 |
|
{ |
70 |
16 |
String[] classNames = container.getAttribute(CLASS_ATTRIBUTE).split("\\s+"); |
71 |
16 |
if (classNames.length < 2) { |
72 |
0 |
return null; |
73 |
|
} |
74 |
16 |
return classNames[1].substring("extension-item-".length()); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
@return |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
80 |
9 |
public String getStatusMessage()... |
81 |
|
{ |
82 |
9 |
By xpath = By.xpath("*[@class = 'extension-header']//*[@class = 'extension-status']"); |
83 |
9 |
List<WebElement> found = getDriver().findElementsWithoutWaiting(container, xpath); |
84 |
9 |
return found.size() > 0 ? found.get(0).getText() : null; |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
@return |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
3 |
public ExtensionId getId()... |
91 |
|
{ |
92 |
3 |
return new ExtensionId(getName(), getVersion()); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
@return |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
98 |
12 |
public String getName()... |
99 |
|
{ |
100 |
12 |
By xpath = By.xpath("*[@class = 'extension-header']//*[@class = 'extension-name']"); |
101 |
12 |
return getDriver().findElementWithoutWaiting(container, xpath).getText(); |
102 |
|
} |
103 |
|
|
104 |
|
|
105 |
|
@return |
106 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
107 |
7 |
public String getVersion()... |
108 |
|
{ |
109 |
7 |
By xpath = By.xpath("*[@class = 'extension-header']//*[@class = 'extension-version']"); |
110 |
7 |
return getDriver().findElementWithoutWaiting(container, xpath).getText(); |
111 |
|
} |
112 |
|
|
113 |
|
|
114 |
|
@return |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
116 |
1 |
public List<WebElement> getAuthors()... |
117 |
|
{ |
118 |
1 |
return getDriver().findElementsWithoutWaiting(container, By.className("extension-author")); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
@return |
123 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
124 |
2 |
public String getSummary()... |
125 |
|
{ |
126 |
2 |
List<WebElement> found = getDriver().findElementsWithoutWaiting(container, By.className("extension-summary")); |
127 |
2 |
return found.size() > 0 ? found.get(0).getText() : null; |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@return |
134 |
|
|
|
|
| 57.1% |
Uncovered Elements: 3 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
135 |
2 |
public ExtensionPane showDetails()... |
136 |
|
{ |
137 |
2 |
WebElement showDetailsButton = getShowDetailsButton(); |
138 |
2 |
if (showDetailsButton.getAttribute(CLASS_ATTRIBUTE).contains("visibilityAction")) { |
139 |
|
|
140 |
0 |
showDetailsButton.click(); |
141 |
0 |
return this; |
142 |
|
} else { |
143 |
|
|
144 |
2 |
return clickAndWaitUntilElementIsVisible(showDetailsButton, "/*[@class = 'extension-body']"); |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
@return |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
2 |
public WebElement getShowDetailsButton()... |
152 |
|
{ |
153 |
2 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "showDetails", "Show details"))); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
@param |
160 |
|
@param |
161 |
|
@return |
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
163 |
27 |
private ExtensionPane clickAndWaitUntilElementIsVisible(WebElement button, String xpathSuffix)... |
164 |
|
{ |
165 |
27 |
String xpath = getXPath(); |
166 |
27 |
button.click(); |
167 |
27 |
getDriver().waitUntilElementIsVisible(By.xpath(xpath + xpathSuffix)); |
168 |
|
|
169 |
27 |
return new ExtensionPane(getDriver().findElementWithoutWaiting(By.xpath(xpath))); |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
@return |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
175 |
27 |
private String getXPath()... |
176 |
|
{ |
177 |
27 |
String nameAndVersion = |
178 |
|
getDriver().findElementWithoutWaiting(container, By.className("extension-title")).getText(); |
179 |
27 |
return String.format("//form[contains(@class, 'extension-item') and descendant::*[" |
180 |
|
+ "contains(@class, 'extension-title') and normalize-space(.) = '%s']]", nameAndVersion); |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
@return |
187 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
188 |
0 |
public ExtensionPane hideDetails()... |
189 |
|
{ |
190 |
0 |
getHideDetailsButton().click(); |
191 |
0 |
return this; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
|
@return |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
197 |
0 |
public WebElement getHideDetailsButton()... |
198 |
|
{ |
199 |
0 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "hideDetails", "Hide details"))); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
@param |
206 |
|
@return |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
25 |
private ExtensionPane clickAndWaitForConfirmationOrJobDone(WebElement button)... |
209 |
|
{ |
210 |
|
|
211 |
|
|
212 |
25 |
return clickAndWaitUntilElementIsVisible(button, |
213 |
|
"[descendant::button[@name = 'extensionAction' and @value = 'continue' and not(@disabled)] or (" |
214 |
|
+ "not(contains(@class, 'loading')) and descendant::*[@class = 'extension-body']" |
215 |
|
+ "/*[@class = 'extension-body-progress extension-body-section'])]"); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@return |
222 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
223 |
5 |
public ExtensionPane install()... |
224 |
|
{ |
225 |
5 |
return maybeOpenActionDropDownMenu().clickAndWaitForConfirmationOrJobDone(getInstallButton()); |
226 |
|
} |
227 |
|
|
228 |
|
|
229 |
|
@return |
230 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
231 |
6 |
public WebElement getInstallButton()... |
232 |
|
{ |
233 |
6 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "install", "Install"))); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
@param |
238 |
|
@return |
239 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
240 |
33 |
private WebElement maybeFindElement(By locator)... |
241 |
|
{ |
242 |
33 |
List<WebElement> found = getDriver().findElementsWithoutWaiting(container, locator); |
243 |
33 |
return found.size() > 0 ? found.get(0) : null; |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
@return |
250 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
251 |
11 |
private ExtensionPane maybeOpenActionDropDownMenu()... |
252 |
|
{ |
253 |
11 |
String xpath = ".//*[@class = 'extension-actions']//*[@class = 'dropdown-toggle']"; |
254 |
11 |
List<WebElement> found = getDriver().findElementsWithoutWaiting(container, By.xpath(xpath)); |
255 |
11 |
if (found.size() > 0) { |
256 |
7 |
found.get(0).click(); |
257 |
|
} |
258 |
11 |
return this; |
259 |
|
} |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
@return |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
266 |
3 |
public ExtensionPane uninstall()... |
267 |
|
{ |
268 |
3 |
return maybeOpenActionDropDownMenu().clickAndWaitForConfirmationOrJobDone(getUninstallButton()); |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
@return |
273 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
274 |
6 |
public WebElement getUninstallButton()... |
275 |
|
{ |
276 |
6 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "uninstall", "Uninstall"))); |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
@return |
283 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
2 |
public ExtensionPane upgrade()... |
285 |
|
{ |
286 |
2 |
return maybeOpenActionDropDownMenu().clickAndWaitForConfirmationOrJobDone(getUpgradeButton()); |
287 |
|
} |
288 |
|
|
289 |
|
|
290 |
|
@return |
291 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
292 |
3 |
public WebElement getUpgradeButton()... |
293 |
|
{ |
294 |
3 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "install", "Upgrade"))); |
295 |
|
} |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
|
|
300 |
|
@return |
301 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
1 |
public ExtensionPane downgrade()... |
303 |
|
{ |
304 |
1 |
return maybeOpenActionDropDownMenu().clickAndWaitForConfirmationOrJobDone(getDowngradeButton()); |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
@return |
309 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
310 |
2 |
public WebElement getDowngradeButton()... |
311 |
|
{ |
312 |
2 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "install", "Downgrade"))); |
313 |
|
} |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
@return |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
320 |
14 |
public ExtensionPane confirm()... |
321 |
|
{ |
322 |
14 |
return clickAndWaitForConfirmationOrJobDone(getContinueButton()); |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
@return |
327 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
328 |
14 |
public WebElement getContinueButton()... |
329 |
|
{ |
330 |
14 |
return maybeFindElement(By.xpath(String.format(ACTION_BUTTON_XPATH, "continue", "Continue"))); |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
@param |
337 |
|
@return |
338 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
339 |
20 |
private WebElement clickTab(String label)... |
340 |
|
{ |
341 |
20 |
By tabXPath = By.xpath(".//*[@class = 'innerMenu']//a[normalize-space(.) = '" + label + "']"); |
342 |
20 |
List<WebElement> found = getDriver().findElementsWithoutWaiting(container, tabXPath); |
343 |
20 |
if (found.size() == 0) { |
344 |
0 |
return null; |
345 |
|
} |
346 |
20 |
String sectionAnchor = StringUtils.substringAfterLast(found.get(0).getAttribute("href"), "#"); |
347 |
20 |
found.get(0).click(); |
348 |
20 |
By sectionXPath = |
349 |
|
By.xpath(".//*[contains(@class, 'extension-body-section') and preceding-sibling::*[1][@id = '" |
350 |
|
+ sectionAnchor + "']]"); |
351 |
20 |
return getDriver().findElementWithoutWaiting(container, sectionXPath); |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
@return |
358 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
359 |
2 |
public ExtensionDescriptionPane openDescriptionSection()... |
360 |
|
{ |
361 |
2 |
WebElement section = clickTab("Description"); |
362 |
2 |
return section != null ? new ExtensionDescriptionPane(section) : null; |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
@return |
369 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
370 |
3 |
public ExtensionDependenciesPane openDependenciesSection()... |
371 |
|
{ |
372 |
3 |
WebElement section = clickTab("Dependencies"); |
373 |
3 |
return section != null ? new ExtensionDependenciesPane(section) : null; |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
@return |
380 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
381 |
15 |
public ExtensionProgressPane openProgressSection()... |
382 |
|
{ |
383 |
15 |
WebElement section = clickTab("Progress"); |
384 |
15 |
return section != null ? new ExtensionProgressPane(section) : null; |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
@return |
389 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
390 |
2 |
public ProgressBarPane getProgressBar()... |
391 |
|
{ |
392 |
2 |
List<WebElement> found = getDriver().findElementsWithoutWaiting(container, By.className("ui-progress")); |
393 |
2 |
return found.size() != 1 ? null : new ProgressBarPane(found.get(0)); |
394 |
|
} |
395 |
|
} |