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 java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.openqa.selenium.By; |
26 |
|
import org.openqa.selenium.WebElement; |
27 |
|
import org.openqa.selenium.support.ui.Select; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
@version |
33 |
|
@since |
34 |
|
|
|
|
| 87.9% |
Uncovered Elements: 7 (58) |
Complexity: 17 |
Complexity Density: 0.46 |
|
35 |
|
public class StaticListClassFieldEditPane extends ClassFieldEditPane |
36 |
|
{ |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
private WebElement defaultValueContainer; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@param |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
47 |
3 |
public StaticListClassFieldEditPane(String fieldName)... |
48 |
|
{ |
49 |
3 |
super(fieldName); |
50 |
|
|
51 |
3 |
defaultValueContainer = getContainer().findElement(By.xpath(".//dl[@class = 'field-viewer']/dd")); |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
@return |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
6 |
public Select getDisplayTypeSelect()... |
58 |
|
{ |
59 |
6 |
return new Select(getPropertyInput("displayType")); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
@return |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
3 |
public WebElement getSizeInput()... |
66 |
|
{ |
67 |
3 |
return getPropertyInput("size"); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
@return |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
6 |
public WebElement getMultipleSelectionCheckBox()... |
74 |
|
{ |
75 |
6 |
return getPropertyInput("multiSelect"); |
76 |
|
} |
77 |
|
|
|
|
| 62.5% |
Uncovered Elements: 3 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
78 |
1 |
@Override... |
79 |
|
public String getDefaultValue() |
80 |
|
{ |
81 |
1 |
String displayType = getPreviewInputType(); |
82 |
1 |
if ("input".equals(displayType)) { |
83 |
0 |
return super.getDefaultValue(); |
84 |
|
} else { |
85 |
1 |
for (WebElement selectedItem : getSelectedItems()) { |
86 |
|
|
87 |
1 |
return selectedItem.getAttribute("value"); |
88 |
|
} |
89 |
|
} |
90 |
0 |
return null; |
91 |
|
} |
92 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
93 |
1 |
@Override... |
94 |
|
public void setDefaultValue(String defaultValue) |
95 |
|
{ |
96 |
1 |
if ("input".equals(getPreviewInputType())) { |
97 |
0 |
super.setDefaultValue(defaultValue); |
98 |
|
} else { |
99 |
|
|
100 |
1 |
for (WebElement selectedItem : getSelectedItems()) { |
101 |
2 |
selectedItem.click(); |
102 |
|
} |
103 |
|
|
104 |
1 |
getItemByValue(defaultValue).click(); |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@return |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
113 |
2 |
public List<String> getDefaultSelectedValues()... |
114 |
|
{ |
115 |
2 |
List<String> selectedValues = new ArrayList<String>(); |
116 |
2 |
for (WebElement selectedItem : getSelectedItems()) { |
117 |
4 |
selectedValues.add(selectedItem.getAttribute("value")); |
118 |
|
} |
119 |
2 |
return selectedValues; |
120 |
|
} |
121 |
|
|
122 |
|
|
123 |
|
@return |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
125 |
4 |
protected List<WebElement> getSelectedItems()... |
126 |
|
{ |
127 |
4 |
By xpath = By.xpath(".//*[local-name() = 'option' or @type = 'radio' or @type = 'checkbox']"); |
128 |
4 |
List<WebElement> selectedItems = new ArrayList<WebElement>(); |
129 |
4 |
for (WebElement item : getDriver().findElementsWithoutWaiting(defaultValueContainer, xpath)) { |
130 |
13 |
if (item.isSelected()) { |
131 |
7 |
selectedItems.add(item); |
132 |
|
} |
133 |
|
} |
134 |
4 |
return selectedItems; |
135 |
|
} |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
@return |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
143 |
6 |
public WebElement getItemByValue(String value)... |
144 |
|
{ |
145 |
6 |
By xpath = By.xpath(".//*[@value = '" + value + "']"); |
146 |
6 |
try { |
147 |
6 |
return getDriver().findElementWithoutWaiting(defaultValueContainer, xpath); |
148 |
|
} catch (Exception e) { |
149 |
1 |
return null; |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
@link |
156 |
|
|
|
|
| 80% |
Uncovered Elements: 2 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
157 |
5 |
public String getPreviewInputType()... |
158 |
|
{ |
159 |
5 |
By xpath = By.xpath(".//*[local-name() = 'select' or (local-name() = 'input' and not(@type = 'hidden'))]"); |
160 |
5 |
List<WebElement> inputs = getDriver().findElementsWithoutWaiting(defaultValueContainer, xpath); |
161 |
5 |
if (inputs.size() > 0) { |
162 |
5 |
WebElement input = inputs.get(0); |
163 |
5 |
return "select".equalsIgnoreCase(input.getTagName()) ? "select" : input.getAttribute("type").toLowerCase(); |
164 |
|
} |
165 |
0 |
return null; |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
@return |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
1 |
public StaticListItemsEditor getItemsEditor()... |
172 |
|
{ |
173 |
1 |
return new StaticListItemsEditor(getDriver().findElementWithoutWaiting(getContainer(), |
174 |
|
By.className("staticListEditor"))); |
175 |
|
} |
176 |
|
} |