| 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.HashMap; |
| 24 |
|
import java.util.List; |
| 25 |
|
import java.util.Locale; |
| 26 |
|
import java.util.Map; |
| 27 |
|
|
| 28 |
|
import org.apache.commons.lang3.LocaleUtils; |
| 29 |
|
import org.openqa.selenium.By; |
| 30 |
|
import org.openqa.selenium.WebElement; |
| 31 |
|
import org.openqa.selenium.support.FindBy; |
| 32 |
|
import org.openqa.selenium.support.ui.Select; |
| 33 |
|
import org.xwiki.test.ui.po.BasePage; |
| 34 |
|
import org.xwiki.test.ui.po.InlinePage; |
| 35 |
|
import org.xwiki.test.ui.po.ViewPage; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@version |
| 41 |
|
@since |
| 42 |
|
|
| |
|
| 66.2% |
Uncovered Elements: 22 (65) |
Complexity: 21 |
Complexity Density: 0.52 |
|
| 43 |
|
public class EditPage extends BasePage |
| 44 |
|
{ |
| 45 |
|
@FindBy(name = "action_saveandcontinue") |
| 46 |
|
protected WebElement saveandcontinue; |
| 47 |
|
|
| 48 |
|
@FindBy(name = "action_save") |
| 49 |
|
protected WebElement save; |
| 50 |
|
|
| 51 |
|
@FindBy(name = "action_cancel") |
| 52 |
|
protected WebElement cancel; |
| 53 |
|
|
| 54 |
|
@FindBy(id = "editcolumn") |
| 55 |
|
protected WebElement currentEditorDiv; |
| 56 |
|
|
| 57 |
|
@FindBy(id = "xwikidocsyntaxinput2") |
| 58 |
|
protected WebElement syntaxIdSelect; |
| 59 |
|
|
| 60 |
|
@FindBy(name = "parent") |
| 61 |
|
private WebElement parentInput; |
| 62 |
|
|
| 63 |
|
@FindBy(id = "xwikidoctitleinput") |
| 64 |
|
private WebElement titleField; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
@FindBy(id = "editmenu") |
| 70 |
|
private WebElement editMenuBar; |
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
@FindBy(id = "tmCurrentEditor") |
| 76 |
|
private WebElement currentEditorMenu; |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 81 |
|
public enum Editor |
| 82 |
|
{ |
| 83 |
|
WYSIWYG("WYSIWYG"), |
| 84 |
|
WIKI("Wiki"), |
| 85 |
|
RIGHTS("Access Rights"), |
| 86 |
|
OBJECT("Objects"), |
| 87 |
|
CLASS("Class"); |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
private static final Map<String, Editor> BY_PRETTY_NAME = new HashMap<String, Editor>(); |
| 93 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 94 |
1 |
static {... |
| 95 |
|
|
| 96 |
|
|
| 97 |
1 |
for (Editor editor : values()) { |
| 98 |
5 |
BY_PRETTY_NAME.put(editor.getPrettyName(), editor); |
| 99 |
|
} |
| 100 |
|
} |
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
private final String prettyName; |
| 106 |
|
|
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@param |
| 111 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 112 |
5 |
Editor(String prettyName)... |
| 113 |
|
{ |
| 114 |
5 |
this.prettyName = prettyName; |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
@return |
| 119 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
5 |
public String getPrettyName()... |
| 121 |
|
{ |
| 122 |
5 |
return this.prettyName; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@param |
| 127 |
|
@return |
| 128 |
|
|
| 129 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 130 |
0 |
public static Editor byPrettyName(String prettyName)... |
| 131 |
|
{ |
| 132 |
0 |
return BY_PRETTY_NAME.get(prettyName); |
| 133 |
|
} |
| 134 |
|
} |
| 135 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 136 |
17 |
public void clickSaveAndContinue()... |
| 137 |
|
{ |
| 138 |
17 |
this.clickSaveAndContinue(true); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@link |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
@param |
| 146 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 147 |
18 |
public void clickSaveAndContinue(boolean wait)... |
| 148 |
|
{ |
| 149 |
18 |
this.getSaveAndContinueButton().click(); |
| 150 |
|
|
| 151 |
18 |
if (wait) { |
| 152 |
|
|
| 153 |
17 |
waitForNotificationSuccessMessage("Saved"); |
| 154 |
|
} |
| 155 |
|
} |
| 156 |
|
|
| 157 |
|
|
| 158 |
|
@link@link |
| 159 |
|
@link |
| 160 |
|
|
| 161 |
|
@return |
| 162 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 163 |
18 |
public WebElement getSaveAndContinueButton()... |
| 164 |
|
{ |
| 165 |
18 |
return saveandcontinue; |
| 166 |
|
} |
| 167 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 168 |
89 |
public <T extends ViewPage> T clickSaveAndView()... |
| 169 |
|
{ |
| 170 |
89 |
clickSaveAndView(true); |
| 171 |
|
|
| 172 |
89 |
return (T) new ViewPage(); |
| 173 |
|
} |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
@param |
| 180 |
|
@since |
| 181 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 182 |
89 |
public void clickSaveAndView(boolean wait)... |
| 183 |
|
{ |
| 184 |
89 |
if (wait) { |
| 185 |
89 |
getDriver().addPageNotYetReloadedMarker(); |
| 186 |
|
} |
| 187 |
|
|
| 188 |
89 |
this.getSaveAndViewButton().click(); |
| 189 |
|
|
| 190 |
89 |
if (wait) { |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
|
| 194 |
89 |
getDriver().waitUntilPageIsReloaded(); |
| 195 |
|
} |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
@link@link |
| 200 |
|
@link |
| 201 |
|
|
| 202 |
|
@return |
| 203 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 204 |
74 |
public WebElement getSaveAndViewButton()... |
| 205 |
|
{ |
| 206 |
74 |
return save; |
| 207 |
|
} |
| 208 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 209 |
8 |
public ViewPage clickCancel()... |
| 210 |
|
{ |
| 211 |
8 |
this.cancel.click(); |
| 212 |
8 |
return new ViewPage(); |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
|
| 216 |
|
@return |
| 217 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 218 |
1 |
public Editor getEditor()... |
| 219 |
|
{ |
| 220 |
1 |
String editor = ""; |
| 221 |
1 |
String[] CSSClasses = this.currentEditorDiv.getAttribute("class").split(" "); |
| 222 |
1 |
for (String cssClasse : CSSClasses) { |
| 223 |
2 |
if (cssClasse.startsWith("editor-")) { |
| 224 |
1 |
editor = cssClasse.substring(7); |
| 225 |
1 |
break; |
| 226 |
|
} |
| 227 |
|
} |
| 228 |
1 |
return Editor.valueOf(editor.toUpperCase()); |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
|
| 232 |
|
@return |
| 233 |
|
@since |
| 234 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 235 |
0 |
public String getSyntaxId()... |
| 236 |
|
{ |
| 237 |
0 |
return this.syntaxIdSelect.getAttribute("value"); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
|
| 241 |
|
@since |
| 242 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 243 |
0 |
public void setSyntaxId(String syntaxId)... |
| 244 |
|
{ |
| 245 |
0 |
Select select = new Select(this.syntaxIdSelect); |
| 246 |
0 |
select.selectByValue(syntaxId); |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
|
| 250 |
|
@return |
| 251 |
|
@since |
| 252 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 253 |
2 |
public String getParent()... |
| 254 |
|
{ |
| 255 |
2 |
return this.parentInput.getAttribute("value"); |
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
|
| 259 |
|
@since |
| 260 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 261 |
5 |
@Override... |
| 262 |
|
public String getDocumentTitle() |
| 263 |
|
{ |
| 264 |
5 |
return this.titleField.getAttribute("value"); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
|
| 268 |
|
@since |
| 269 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 270 |
179 |
@Override... |
| 271 |
|
public void waitUntilPageJSIsLoaded() |
| 272 |
|
{ |
| 273 |
179 |
super.waitUntilPageJSIsLoaded(); |
| 274 |
|
|
| 275 |
|
|
| 276 |
179 |
getDriver().waitUntilJavascriptCondition( |
| 277 |
|
"return XWiki.actionButtons != undefined && " + "XWiki.actionButtons.EditActions != undefined && " |
| 278 |
|
+ "XWiki.actionButtons.AjaxSaveAndContinue != undefined"); |
| 279 |
|
} |
| 280 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 281 |
0 |
protected List<Locale> getExistingLocales(List<WebElement> elements)... |
| 282 |
|
{ |
| 283 |
0 |
List<Locale> locales = new ArrayList<>(elements.size()); |
| 284 |
0 |
for (WebElement element : elements) { |
| 285 |
0 |
locales.add(LocaleUtils.toLocale(element.getText())); |
| 286 |
|
} |
| 287 |
|
|
| 288 |
0 |
return locales; |
| 289 |
|
} |
| 290 |
|
|
| 291 |
|
|
| 292 |
|
@return |
| 293 |
|
@since |
| 294 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 295 |
0 |
public List<Locale> getExistingLocales()... |
| 296 |
|
{ |
| 297 |
0 |
List<WebElement> elements = |
| 298 |
|
getDriver().findElementsWithoutWaiting(By.xpath("//p[starts-with(text(), 'Existing translations:')]//a")); |
| 299 |
|
|
| 300 |
0 |
return getExistingLocales(elements); |
| 301 |
|
} |
| 302 |
|
|
| 303 |
|
|
| 304 |
|
@return |
| 305 |
|
@since |
| 306 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 307 |
0 |
public List<Locale> getNotExistingLocales()... |
| 308 |
|
{ |
| 309 |
0 |
List<WebElement> elements = |
| 310 |
|
getDriver().findElementsWithoutWaiting(By.xpath("//p[starts-with(text(), 'Translate this page in:')]//a")); |
| 311 |
|
|
| 312 |
0 |
return getExistingLocales(elements); |
| 313 |
|
} |
| 314 |
|
|
| 315 |
|
|
| 316 |
|
@param |
| 317 |
|
@return |
| 318 |
|
@since |
| 319 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 320 |
0 |
public WikiEditPage clickTranslate(String locale)... |
| 321 |
|
{ |
| 322 |
0 |
WebElement element = getDriver().findElementWithoutWaiting( |
| 323 |
|
By.xpath("//p[starts-with(text(), 'Translate this page in:')]//a[text()='" + locale + "']")); |
| 324 |
|
|
| 325 |
0 |
element.click(); |
| 326 |
|
|
| 327 |
0 |
return new WikiEditPage(); |
| 328 |
|
} |
| 329 |
|
} |