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.editor; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.apache.commons.lang3.StringUtils; |
26 |
|
import org.openqa.selenium.By; |
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.po.BaseElement; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (57) |
Complexity: 18 |
Complexity Density: 0.46 |
|
39 |
|
public class UserPicker extends BaseElement |
40 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 9 |
Complexity Density: 0.75 |
|
41 |
|
public static class UserElement extends BaseElement |
42 |
|
{ |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
private WebElement container; |
47 |
|
|
48 |
|
|
49 |
|
@link |
50 |
|
|
51 |
|
@param |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
53 |
33 |
public UserElement(WebElement container)... |
54 |
|
{ |
55 |
33 |
this.container = container; |
56 |
|
} |
57 |
|
|
58 |
|
|
59 |
|
@return |
60 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
19 |
public WebElement getAvatar()... |
62 |
|
{ |
63 |
19 |
return getDriver().findElementWithoutWaiting(container, By.className("icon")); |
64 |
|
} |
65 |
|
|
66 |
|
|
67 |
|
@return |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
69 |
20 |
public String getName()... |
70 |
|
{ |
71 |
20 |
String name = getDriver().findElementWithoutWaiting(container, By.className("user-name")).getText(); |
72 |
|
|
73 |
20 |
List<WebElement> delete = getDriver().findElementsWithoutWaiting(container, By.className("delete-tool")); |
74 |
20 |
if (delete.size() > 0) { |
75 |
14 |
name = StringUtils.removeEnd(name, delete.get(0).getText()); |
76 |
|
} |
77 |
20 |
return name; |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
@return |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
19 |
public String getAlias()... |
84 |
|
{ |
85 |
19 |
return getDriver().findElementWithoutWaiting(container, By.className("user-alias")).getText(); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
@return |
90 |
|
|
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
1 |
public String getText()... |
93 |
|
{ |
94 |
1 |
return container.getText(); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
100 |
3 |
public void delete()... |
101 |
|
{ |
102 |
3 |
new Actions(getDriver()).moveToElement(container).click(getDriver().findElementWithoutWaiting(container, |
103 |
|
By.className("delete-tool"))).perform(); |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
1 |
public void moveMouseOver()... |
110 |
|
{ |
111 |
1 |
new Actions(getDriver()).moveToElement(container).perform(); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@param |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
1 |
public void moveBefore(UserElement user)... |
120 |
|
{ |
121 |
1 |
new Actions(getDriver()).clickAndHold(container).moveToElement(user.container, 0, 0).release().perform(); |
122 |
|
} |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
private final WebElement textInput; |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
135 |
19 |
public UserPicker(WebElement textInput)... |
136 |
|
{ |
137 |
19 |
this.textInput = textInput; |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
@param |
144 |
|
@return |
145 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
146 |
34 |
public UserPicker sendKeys(CharSequence... keysToSend)... |
147 |
|
{ |
148 |
34 |
textInput.sendKeys(keysToSend); |
149 |
34 |
return this; |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@return |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
157 |
3 |
public UserPicker clear()... |
158 |
|
{ |
159 |
3 |
textInput.clear(); |
160 |
3 |
return this; |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
@return |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
166 |
10 |
public String getValue()... |
167 |
|
{ |
168 |
10 |
return textInput.getAttribute("value"); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
@return |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
174 |
10 |
public WebElement getClearSelectionLink()... |
175 |
|
{ |
176 |
10 |
String xpath = "preceding-sibling::a[@class = 'clear-tool' and position() = last()]"; |
177 |
10 |
return getDriver().findElementWithoutWaiting(textInput, By.xpath(xpath)); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
@return |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
185 |
24 |
public UserPicker waitForSuggestions()... |
186 |
|
{ |
187 |
24 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
188 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
67 |
public Boolean apply(WebDriver driver)... |
190 |
|
{ |
191 |
67 |
return !textInput.getAttribute("class").contains("loading") && isSuggestListDisplayed(driver); |
192 |
|
} |
193 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
194 |
67 |
private boolean isSuggestListDisplayed(WebDriver driver)... |
195 |
|
{ |
196 |
67 |
WebElement suggestItems = driver.findElement(By.className("suggestItems")); |
197 |
|
|
198 |
|
|
199 |
47 |
WebElement suggestList = suggestItems.findElement(By.className("suggestList")); |
200 |
|
|
201 |
24 |
return suggestList.isDisplayed() && Double.parseDouble(suggestItems.getCssValue("opacity")) == 1; |
202 |
|
} |
203 |
|
}); |
204 |
23 |
return this; |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
@param |
211 |
|
@return |
212 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
213 |
14 |
private UserPicker waitForSuggestionsToDisappear(int timeout)... |
214 |
|
{ |
215 |
14 |
int previousTimeout = getDriver().getTimeout(); |
216 |
14 |
getDriver().setTimeout(timeout); |
217 |
14 |
try { |
218 |
14 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
219 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
220 |
157 |
public Boolean apply(WebDriver driver)... |
221 |
|
{ |
222 |
157 |
return driver.findElements(By.className("suggestItems")).size() == 0; |
223 |
|
} |
224 |
|
}); |
225 |
|
} finally { |
226 |
14 |
getDriver().setTimeout(previousTimeout); |
227 |
|
} |
228 |
13 |
return this; |
229 |
|
} |
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
@return |
235 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
236 |
10 |
public UserPicker waitForSuggestionsToFadeOut()... |
237 |
|
{ |
238 |
10 |
return waitForSuggestionsToDisappear(2); |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@return |
245 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
246 |
4 |
public UserPicker waitForSuggestionsToDisappear()... |
247 |
|
{ |
248 |
4 |
return waitForSuggestionsToDisappear(35); |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
@param |
255 |
|
@return |
256 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
257 |
5 |
public UserPicker select(String userNameOrAlias)... |
258 |
|
{ |
259 |
5 |
getDriver().findElementWithoutWaiting( |
260 |
|
By.xpath("//ul[@class = 'xlist suggestList']/li[contains(., '" + userNameOrAlias + "')]")).click(); |
261 |
5 |
return this; |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
@return |
266 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
267 |
7 |
public List<UserElement> getSuggestions()... |
268 |
|
{ |
269 |
7 |
List<UserElement> suggestions = new ArrayList<UserElement>(); |
270 |
7 |
for (WebElement item : getDriver().findElementsWithoutWaiting( |
271 |
|
By.xpath("//ul[@class = 'xlist suggestList']/li"))) |
272 |
|
{ |
273 |
13 |
suggestions.add(new UserElement(item)); |
274 |
|
} |
275 |
7 |
return suggestions; |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
@return |
280 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
281 |
15 |
public List<UserElement> getAcceptedSuggestions()... |
282 |
|
{ |
283 |
15 |
List<UserElement> acceptedSuggestions = new ArrayList<UserElement>(); |
284 |
15 |
for (WebElement item : getDriver().findElementsWithoutWaiting(textInput, |
285 |
|
By.xpath("preceding-sibling::ul[contains(@class, 'accepted-suggestions') and position() = last()]/li"))) |
286 |
|
{ |
287 |
19 |
acceptedSuggestions.add(new UserElement(item)); |
288 |
|
} |
289 |
15 |
return acceptedSuggestions; |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
@return |
296 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
297 |
2 |
public UserPicker moveMouseOver()... |
298 |
|
{ |
299 |
2 |
new Actions(getDriver()).moveToElement(textInput).perform(); |
300 |
2 |
return this; |
301 |
|
} |
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
@return |
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
309 |
11 |
public UserPicker waitToLoad()... |
310 |
|
{ |
311 |
11 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
312 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
313 |
11 |
public Boolean apply(WebDriver driver)... |
314 |
|
{ |
315 |
11 |
String classNames = textInput.getAttribute("class"); |
316 |
11 |
return classNames.contains("initialized") && !classNames.contains("loading"); |
317 |
|
} |
318 |
|
}); |
319 |
11 |
return this; |
320 |
|
} |
321 |
|
} |