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.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.openqa.selenium.By; |
26 |
|
import org.openqa.selenium.WebDriver; |
27 |
|
import org.openqa.selenium.WebDriverException; |
28 |
|
import org.openqa.selenium.WebElement; |
29 |
|
import org.openqa.selenium.support.FindBy; |
30 |
|
import org.openqa.selenium.support.pagefactory.ByChained; |
31 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
32 |
|
import org.xwiki.test.ui.po.editor.EditPage; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 79.6% |
Uncovered Elements: 22 (108) |
Complexity: 35 |
Complexity Density: 0.53 |
|
40 |
|
public class CreatePagePage extends ViewPage |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@FindBy(className = "location-picker") |
46 |
|
private WebElement documentPickerElement; |
47 |
|
|
48 |
|
private DocumentPicker documentPicker; |
49 |
|
|
50 |
|
@FindBy(id = "terminal") |
51 |
|
private WebElement isTerminalCheckbox; |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
53 |
1 |
public static CreatePagePage gotoPage()... |
54 |
|
{ |
55 |
1 |
getUtil().gotoPage("Main", "WebHome", "create"); |
56 |
1 |
return new CreatePagePage(); |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
@return |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
62 |
61 |
public DocumentPicker getDocumentPicker()... |
63 |
|
{ |
64 |
61 |
if (this.documentPicker == null) { |
65 |
17 |
this.documentPicker = new DocumentPicker(this.documentPickerElement); |
66 |
|
} |
67 |
|
|
68 |
61 |
return this.documentPicker; |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
13 |
private List<WebElement> getAvailableTemplateInputs()... |
72 |
|
{ |
73 |
13 |
return getDriver().findElementsWithoutWaiting(By.xpath("//input[@name = 'type' and @data-type = 'template']")); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
0 |
private List<WebElement> getAvailableTypeInputs()... |
77 |
|
{ |
78 |
0 |
return getDriver().findElementsWithoutWaiting(By.xpath("//input[@name = 'type']")); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
@since |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
84 |
4 |
public int getAvailableTemplateSize()... |
85 |
|
{ |
86 |
4 |
return getAvailableTemplateInputs().size(); |
87 |
|
} |
88 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
89 |
4 |
public List<String> getAvailableTemplates()... |
90 |
|
{ |
91 |
4 |
List<String> availableTemplates = new ArrayList<String>(); |
92 |
4 |
List<WebElement> templateInputs = getAvailableTemplateInputs(); |
93 |
4 |
for (WebElement input : templateInputs) { |
94 |
3 |
if (input.getAttribute("value").length() > 0) { |
95 |
3 |
availableTemplates.add(input.getAttribute("value")); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
4 |
return availableTemplates; |
100 |
|
} |
101 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
102 |
5 |
public void setTemplate(String template)... |
103 |
|
{ |
104 |
5 |
List<WebElement> templates = getAvailableTemplateInputs(); |
105 |
5 |
for (WebElement templateInput : templates) { |
106 |
5 |
if (templateInput.getAttribute("value").equals(template)) { |
107 |
|
|
108 |
5 |
WebElement label = |
109 |
|
getDriver().findElementWithoutWaiting( |
110 |
|
By.xpath("//label[@for = '" + templateInput.getAttribute("id") + "']")); |
111 |
5 |
label.click(); |
112 |
5 |
return; |
113 |
|
} |
114 |
|
} |
115 |
0 |
throw new RuntimeException("Failed to find template [" + template + "]"); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
118 |
0 |
public void setType(String type)... |
119 |
|
{ |
120 |
0 |
List<WebElement> types = getAvailableTypeInputs(); |
121 |
0 |
for (WebElement typeInput : types) { |
122 |
0 |
if (typeInput.getAttribute("value").equals(type)) { |
123 |
|
|
124 |
0 |
WebElement label = |
125 |
|
getDriver().findElementWithoutWaiting( |
126 |
|
By.xpath("//label[@for = '" + typeInput.getAttribute("id") + "']")); |
127 |
0 |
label.click(); |
128 |
0 |
return; |
129 |
|
} |
130 |
|
} |
131 |
0 |
throw new RuntimeException("Failed to find type [" + type + "]"); |
132 |
|
} |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
26 |
public void clickCreate()... |
135 |
|
{ |
136 |
|
|
137 |
26 |
getDriver().findElementWithoutWaiting(By.id("create")).submit(); |
138 |
|
} |
139 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
2 |
public EditPage createPage(String spaceValue, String pageValue)... |
141 |
|
{ |
142 |
2 |
return createPage(spaceValue, pageValue, false); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
3 |
public EditPage createPage(String spaceValue, String pageValue, boolean isTerminalPage)... |
146 |
|
{ |
147 |
3 |
return createPage(null, spaceValue, pageValue, isTerminalPage); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
|
@since |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
153 |
10 |
public EditPage createPage(String title, String spaceValue, String pageValue, boolean isTerminalPage)... |
154 |
|
{ |
155 |
10 |
fillForm(title, spaceValue, pageValue, isTerminalPage); |
156 |
10 |
clickCreate(); |
157 |
10 |
return new EditPage(); |
158 |
|
} |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
1 |
public EditPage createPageFromTemplate(String spaceValue, String pageValue, String templateValue)... |
161 |
|
{ |
162 |
1 |
return createPageFromTemplate(null, spaceValue, pageValue, templateValue); |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
2 |
public EditPage createPageFromTemplate(String title, String spaceValue, String pageValue, String templateValue)... |
166 |
|
{ |
167 |
2 |
return createPageFromTemplate(title, spaceValue, pageValue, templateValue, false); |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
@since |
172 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
0 |
public EditPage createPageFromTemplate(String spaceValue, String pageValue, String templateValue,... |
174 |
|
boolean isTerminalPage) |
175 |
|
{ |
176 |
0 |
return createPageFromTemplate(null, spaceValue, pageValue, templateValue, isTerminalPage); |
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
|
@since |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
182 |
2 |
public EditPage createPageFromTemplate(String title, String spaceValue, String pageValue, String templateValue,... |
183 |
|
boolean isTerminalPage) |
184 |
|
{ |
185 |
2 |
fillForm(title, spaceValue, pageValue, isTerminalPage); |
186 |
2 |
setTemplate(templateValue); |
187 |
2 |
clickCreate(); |
188 |
2 |
return new EditPage(); |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
|
@param |
193 |
|
@param |
194 |
|
@param |
195 |
|
@param |
196 |
|
@since |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
198 |
13 |
public void fillForm(String title, String spaceReference, String pageName, boolean isTerminalPage)... |
199 |
|
{ |
200 |
13 |
if (title != null) { |
201 |
9 |
getDocumentPicker().setTitle(title); |
202 |
|
} |
203 |
|
|
204 |
13 |
if (spaceReference != null) { |
205 |
12 |
getDocumentPicker().setParent(spaceReference); |
206 |
|
} |
207 |
|
|
208 |
13 |
if (pageName != null) { |
209 |
4 |
getDocumentPicker().setName(pageName); |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
13 |
if (isTerminalPage) { |
216 |
1 |
setTerminalPage(isTerminalPage); |
217 |
|
} |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@since |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
225 |
3 |
public void waitForErrorMessage()... |
226 |
|
{ |
227 |
3 |
getDriver().waitUntilElementIsVisible(By.className("errormessage")); |
228 |
|
} |
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@since |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
1 |
public void waitForFieldErrorMessage()... |
236 |
|
{ |
237 |
1 |
getDriver().waitUntilElementIsVisible(new ByChained(By.className("LV_invalid"))); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
@return |
242 |
|
@since |
243 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
244 |
0 |
public boolean isTerminalPage()... |
245 |
|
{ |
246 |
0 |
return this.isTerminalCheckbox.isSelected(); |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
|
@param |
251 |
|
@since |
252 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
253 |
2 |
public void setTerminalPage(boolean isTerminalPage)... |
254 |
|
{ |
255 |
2 |
if (isTerminalPage != this.isTerminalCheckbox.isSelected()) { |
256 |
2 |
this.isTerminalCheckbox.click(); |
257 |
|
} |
258 |
|
} |
259 |
|
|
260 |
|
|
261 |
|
@return |
262 |
|
@since |
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
264 |
1 |
public boolean isTerminalOptionDisplayed()... |
265 |
|
{ |
266 |
1 |
List<WebElement> elements = getDriver().findElementsWithoutWaiting(By.id("terminal")); |
267 |
1 |
return elements.size() > 0 && elements.get(0).isDisplayed(); |
268 |
|
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
@link |
276 |
|
@link |
277 |
|
|
278 |
|
|
279 |
|
@link |
280 |
|
|
281 |
|
@param |
282 |
|
@since |
283 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
284 |
7 |
public void waitForLocationPreviewContent(final String expectedPathString)... |
285 |
|
{ |
286 |
|
|
287 |
7 |
final StringBuilder currentValue = new StringBuilder(); |
288 |
|
|
289 |
7 |
try { |
290 |
7 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
291 |
|
{ |
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
292 |
10 |
@Override... |
293 |
|
public Boolean apply(WebDriver driver) |
294 |
|
{ |
295 |
10 |
try { |
296 |
10 |
String value = getDocumentPicker().getLocation().getPathAsString(); |
297 |
|
|
298 |
10 |
currentValue.setLength(0); |
299 |
10 |
currentValue.append(value); |
300 |
|
|
301 |
10 |
return expectedPathString.equals(value); |
302 |
|
} catch (Exception e) { |
303 |
0 |
return false; |
304 |
|
} |
305 |
|
} |
306 |
|
}); |
307 |
|
} catch (WebDriverException e) { |
308 |
|
|
309 |
0 |
throw new WebDriverException(String.format("Found [%s], was expecting [%s]", currentValue.toString(), |
310 |
|
expectedPathString), e); |
311 |
|
} |
312 |
|
} |
313 |
|
} |