| 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.ui.ExpectedCondition; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@version |
| 35 |
|
@since |
| 36 |
|
|
| |
|
| 77% |
Uncovered Elements: 14 (61) |
Complexity: 24 |
Complexity Density: 0.6 |
|
| 37 |
|
public class DocumentPicker extends BaseElement |
| 38 |
|
{ |
| 39 |
|
protected WebElement container; |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
15 |
public DocumentPicker()... |
| 45 |
|
{ |
| 46 |
15 |
this.container = getDriver().findElementByClassName("location-picker"); |
| 47 |
|
} |
| 48 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 49 |
25 |
public DocumentPicker(WebElement container)... |
| 50 |
|
{ |
| 51 |
25 |
this.container = container; |
| 52 |
|
} |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 54 |
17 |
public String getTitle()... |
| 55 |
|
{ |
| 56 |
17 |
return getTitleInput().getAttribute("value"); |
| 57 |
|
} |
| 58 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 59 |
29 |
public DocumentPicker setTitle(String title)... |
| 60 |
|
{ |
| 61 |
29 |
getDriver().setTextInputValue(getTitleInput(), title); |
| 62 |
29 |
return this; |
| 63 |
|
} |
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 65 |
51 |
public WebElement getTitleInput()... |
| 66 |
|
{ |
| 67 |
51 |
return this.container.findElement(By.className("location-title-field")); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
19 |
public BreadcrumbElement getLocation()... |
| 71 |
|
{ |
| 72 |
19 |
return new BreadcrumbElement(this.container.findElement(By.className("breadcrumb"))); |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 75 |
14 |
public DocumentPicker toggleLocationAdvancedEdit()... |
| 76 |
|
{ |
| 77 |
14 |
this.container.findElement(By.className("location-action-edit")).click(); |
| 78 |
14 |
return this; |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
1 |
public String getParent()... |
| 82 |
|
{ |
| 83 |
1 |
return getParentInput().getAttribute("value"); |
| 84 |
|
} |
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 86 |
28 |
public DocumentPicker setParent(String parent)... |
| 87 |
|
{ |
| 88 |
28 |
return setAdvancedField(getParentInput(), parent); |
| 89 |
|
} |
| 90 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 91 |
30 |
public WebElement getParentInput()... |
| 92 |
|
{ |
| 93 |
30 |
return this.container.findElement(By.className("location-parent-field")); |
| 94 |
|
} |
| 95 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
3 |
public String getName()... |
| 97 |
|
{ |
| 98 |
3 |
return getNameInput().getAttribute("value"); |
| 99 |
|
} |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
17 |
public DocumentPicker setName(String name)... |
| 102 |
|
{ |
| 103 |
17 |
return setAdvancedField(getNameInput(), name); |
| 104 |
|
} |
| 105 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 106 |
20 |
public WebElement getNameInput()... |
| 107 |
|
{ |
| 108 |
20 |
return this.container.findElement(By.className("location-name-field")); |
| 109 |
|
} |
| 110 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 111 |
45 |
private DocumentPicker setAdvancedField(WebElement field, String value)... |
| 112 |
|
{ |
| 113 |
45 |
if (!field.isDisplayed()) { |
| 114 |
1 |
toggleLocationAdvancedEdit(); |
| 115 |
|
} |
| 116 |
45 |
getDriver().setTextInputValue(field, value); |
| 117 |
45 |
return this; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
2 |
public void browseDocuments()... |
| 128 |
|
{ |
| 129 |
2 |
this.container.findElement(By.className("location-action-pick")).click(); |
| 130 |
|
} |
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
|
| 135 |
|
|
| 136 |
|
|
| 137 |
|
@link |
| 138 |
|
@link |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
@param |
| 142 |
|
@since |
| 143 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 144 |
0 |
public void waitForLocation(final String expectedPathString)... |
| 145 |
|
{ |
| 146 |
|
|
| 147 |
0 |
final StringBuilder currentValue = new StringBuilder(); |
| 148 |
|
|
| 149 |
0 |
try { |
| 150 |
0 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
| 151 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 152 |
0 |
@Override... |
| 153 |
|
public Boolean apply(WebDriver driver) |
| 154 |
|
{ |
| 155 |
0 |
try { |
| 156 |
0 |
String value = getLocation().getPathAsString(); |
| 157 |
|
|
| 158 |
0 |
currentValue.setLength(0); |
| 159 |
0 |
currentValue.append(value); |
| 160 |
|
|
| 161 |
0 |
return expectedPathString.equals(value); |
| 162 |
|
} catch (Exception e) { |
| 163 |
0 |
return false; |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
}); |
| 167 |
|
} catch (WebDriverException e) { |
| 168 |
|
|
| 169 |
0 |
throw new WebDriverException(String.format("Found [%s], was expecting [%s]", currentValue.toString(), |
| 170 |
|
expectedPathString), e); |
| 171 |
|
} |
| 172 |
|
} |
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
@link |
| 180 |
|
@link |
| 181 |
|
|
| 182 |
|
|
| 183 |
|
@param |
| 184 |
|
@since |
| 185 |
|
|
| |
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 186 |
4 |
public void waitForLocation(final List<String> expectedPath)... |
| 187 |
|
{ |
| 188 |
|
|
| 189 |
4 |
final List<String> currentPath = new ArrayList<String>(); |
| 190 |
|
|
| 191 |
4 |
try { |
| 192 |
4 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
| 193 |
|
{ |
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 194 |
7 |
@Override... |
| 195 |
|
public Boolean apply(WebDriver driver) |
| 196 |
|
{ |
| 197 |
7 |
try { |
| 198 |
7 |
List<String> path = getLocation().getPath(); |
| 199 |
|
|
| 200 |
7 |
currentPath.clear(); |
| 201 |
7 |
currentPath.addAll(path); |
| 202 |
|
|
| 203 |
7 |
return expectedPath.equals(path); |
| 204 |
|
} catch (Exception e) { |
| 205 |
0 |
return false; |
| 206 |
|
} |
| 207 |
|
} |
| 208 |
|
}); |
| 209 |
|
} catch (WebDriverException e) { |
| 210 |
|
|
| 211 |
0 |
throw new WebDriverException(String.format("Found %s, was expecting %s", currentPath, expectedPath), e); |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
|
} |