1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.appwithinminutes.test.po; |
21 |
|
|
22 |
|
import org.openqa.selenium.By; |
23 |
|
import org.openqa.selenium.JavascriptExecutor; |
24 |
|
import org.openqa.selenium.NoSuchElementException; |
25 |
|
import org.openqa.selenium.WebElement; |
26 |
|
import org.openqa.selenium.interactions.Actions; |
27 |
|
import org.xwiki.test.ui.po.BaseElement; |
28 |
|
import org.xwiki.test.ui.po.ConfirmationBox; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
@version |
34 |
|
@since |
35 |
|
|
|
|
| 96.5% |
Uncovered Elements: 2 (57) |
Complexity: 18 |
Complexity Density: 0.45 |
|
36 |
|
public class ClassFieldEditPane extends BaseElement |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
private final String fieldName; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
private final WebElement container; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private final WebElement toolBox; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
59 |
71 |
public ClassFieldEditPane(String fieldName)... |
60 |
|
{ |
61 |
71 |
this.fieldName = fieldName; |
62 |
|
|
63 |
|
|
64 |
71 |
By containerLocator = By.id("field-" + fieldName); |
65 |
71 |
getDriver().waitUntilElementIsVisible(containerLocator); |
66 |
|
|
67 |
71 |
container = getDriver().findElement(containerLocator); |
68 |
71 |
toolBox = container.findElement(By.className("toolBox")); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@param |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
76 |
11 |
public void setPrettyName(String prettyName)... |
77 |
|
{ |
78 |
11 |
WebElement prettyNameInput = getPropertyInput("prettyName"); |
79 |
11 |
prettyNameInput.clear(); |
80 |
11 |
prettyNameInput.sendKeys(prettyName); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@param |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
88 |
8 |
public void setDefaultValue(String defaultValue)... |
89 |
|
{ |
90 |
8 |
WebElement defaultValueInput = getDefaultValueInput(); |
91 |
8 |
defaultValueInput.clear(); |
92 |
8 |
defaultValueInput.sendKeys(defaultValue); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
@return |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
4 |
public String getDefaultValue()... |
99 |
|
{ |
100 |
4 |
return getDefaultValueInput().getAttribute("value"); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
@return |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
106 |
27 |
protected WebElement getDefaultValueInput()... |
107 |
|
{ |
108 |
|
|
109 |
|
|
110 |
27 |
String xpath = ".//*[substring(@id, string-length(@id) - %s - 2) = '_0_%s']"; |
111 |
27 |
try { |
112 |
27 |
return getDriver().findElementWithoutWaiting(container, |
113 |
|
By.xpath(String.format(xpath, fieldName.length(), fieldName))); |
114 |
|
} catch (NoSuchElementException e) { |
115 |
|
|
116 |
4 |
return getDriver().findElementWithoutWaiting(container, |
117 |
|
By.xpath(".//dl[@class = 'field-viewer']/dd//*[@name]")); |
118 |
|
} |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
24 |
public void openConfigPanel()... |
125 |
|
{ |
126 |
24 |
clickToolBoxIcon("Configure"); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
132 |
7 |
public void closeConfigPanel()... |
133 |
|
{ |
134 |
7 |
clickToolBoxIcon("Preview"); |
135 |
7 |
String previewXPath = "//*[@id = 'field-" + fieldName + "']//dl[@class = 'field-viewer']/dd"; |
136 |
7 |
getDriver().waitUntilElementHasAttributeValue(By.xpath(previewXPath), "class", ""); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
@param |
143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
144 |
33 |
private void clickToolBoxIcon(String alt)... |
145 |
|
{ |
146 |
|
|
147 |
33 |
new Actions(getDriver()).moveToElement(container).perform(); |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
33 |
showToolBox(); |
152 |
|
|
153 |
33 |
toolBox.findElement(By.xpath("img[@alt = '" + alt + "']")).click(); |
154 |
|
|
155 |
|
|
156 |
33 |
hideToolBox(); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
163 |
34 |
private void showToolBox()... |
164 |
|
{ |
165 |
34 |
((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = 'block';", toolBox); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
@see |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
34 |
private void hideToolBox()... |
174 |
|
{ |
175 |
34 |
((JavascriptExecutor) getDriver()).executeScript("arguments[0].style.display = '';", toolBox); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
@param |
182 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
183 |
16 |
public void setName(String fieldName)... |
184 |
|
{ |
185 |
16 |
WebElement nameInput = getPropertyInput("name"); |
186 |
16 |
nameInput.clear(); |
187 |
16 |
nameInput.sendKeys(fieldName); |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
@return |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
193 |
12 |
public String getName()... |
194 |
|
{ |
195 |
12 |
return getPropertyInput("name").getAttribute("value"); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
@param |
200 |
|
@return |
201 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
202 |
59 |
protected WebElement getPropertyInput(String propertyName)... |
203 |
|
{ |
204 |
59 |
return container.findElement(By.id(String.format("field-%s_%s", this.fieldName, propertyName))); |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
@return |
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
212 |
2 |
public ConfirmationBox delete()... |
213 |
|
{ |
214 |
2 |
clickToolBoxIcon("Delete"); |
215 |
2 |
return new ConfirmationBox(); |
216 |
|
} |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
@param |
222 |
|
@param |
223 |
|
|
224 |
|
@param |
225 |
|
|
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
227 |
1 |
public void dragTo(WebElement element, int xOffset, int yOffset)... |
228 |
|
{ |
229 |
|
|
230 |
1 |
new Actions(getDriver()).moveToElement(container).perform(); |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
1 |
showToolBox(); |
235 |
|
|
236 |
1 |
WebElement dragHandler = toolBox.findElement(By.xpath("img[@alt = 'Move']")); |
237 |
1 |
new Actions(getDriver()).clickAndHold(dragHandler).moveToElement(element, xOffset, yOffset).release().perform(); |
238 |
|
|
239 |
|
|
240 |
1 |
hideToolBox(); |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
|
@return |
245 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
246 |
4 |
protected WebElement getContainer()... |
247 |
|
{ |
248 |
4 |
return container; |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
|
@link |
253 |
|
|
254 |
|
@return |
255 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
256 |
0 |
protected String getFieldName()... |
257 |
|
{ |
258 |
0 |
return fieldName; |
259 |
|
} |
260 |
|
} |