| 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.List; |
| 24 |
|
|
| 25 |
|
import org.openqa.selenium.By; |
| 26 |
|
import org.openqa.selenium.WebDriver; |
| 27 |
|
import org.openqa.selenium.WebElement; |
| 28 |
|
import org.openqa.selenium.support.FindBy; |
| 29 |
|
import org.openqa.selenium.support.ui.ExpectedCondition; |
| 30 |
|
import org.xwiki.test.ui.po.FormElement; |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@version |
| 36 |
|
@since |
| 37 |
|
|
| |
|
| 81% |
Uncovered Elements: 15 (79) |
Complexity: 20 |
Complexity Density: 0.36 |
|
| 38 |
|
public class ObjectEditPage extends EditPage |
| 39 |
|
{ |
| 40 |
|
@FindBy(id = "update") |
| 41 |
|
private WebElement objectForm; |
| 42 |
|
|
| 43 |
|
@FindBy(id = "classname") |
| 44 |
|
private WebElement classNameField; |
| 45 |
|
|
| 46 |
|
@FindBy(name = "action_objectadd") |
| 47 |
|
private WebElement classNameSubmit; |
| 48 |
|
|
| 49 |
|
private FormElement form; |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 54 |
16 |
public static ObjectEditPage gotoPage(String space, String page)... |
| 55 |
|
{ |
| 56 |
16 |
getUtil().gotoPage(space, page, "edit", "editor=object"); |
| 57 |
16 |
return new ObjectEditPage(); |
| 58 |
|
} |
| 59 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 60 |
18 |
public ObjectEditPane addObject(String className)... |
| 61 |
|
{ |
| 62 |
18 |
getForm().setFieldValue(this.classNameField, className); |
| 63 |
|
|
| 64 |
18 |
final By objectsLocator = By.cssSelector("[id='xclass_" + className + "'] .xobject"); |
| 65 |
18 |
final int initialObjectCount = getDriver().findElementsWithoutWaiting(objectsLocator).size(); |
| 66 |
18 |
this.classNameSubmit.click(); |
| 67 |
|
|
| 68 |
|
|
| 69 |
18 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
| 70 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 71 |
36 |
@Override... |
| 72 |
|
public Boolean apply(WebDriver driver) |
| 73 |
|
{ |
| 74 |
36 |
return Boolean.valueOf(driver.findElements(objectsLocator).size() > initialObjectCount); |
| 75 |
|
} |
| 76 |
|
}); |
| 77 |
|
|
| 78 |
18 |
List<ObjectEditPane> objects = getObjectsOfClass(className); |
| 79 |
18 |
return objects.get(objects.size() - 1); |
| 80 |
|
} |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 82 |
1 |
public ObjectEditPane addObjectFromInlineLink(String className)... |
| 83 |
|
{ |
| 84 |
1 |
final By objectsLocator = By.cssSelector("[id='xclass_" + className + "'] .xobject"); |
| 85 |
1 |
final int initialObjectCount = getDriver().findElements(objectsLocator).size(); |
| 86 |
|
|
| 87 |
1 |
getDriver().findElement(By.cssSelector("[id='add_xobject_" + className + "'] .xobject-add-control")).click(); |
| 88 |
|
|
| 89 |
|
|
| 90 |
1 |
getDriver().waitUntilCondition(new ExpectedCondition<Boolean>() |
| 91 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 92 |
2 |
@Override... |
| 93 |
|
public Boolean apply(WebDriver driver) |
| 94 |
|
{ |
| 95 |
2 |
return Boolean.valueOf(driver.findElements(objectsLocator).size() > initialObjectCount); |
| 96 |
|
} |
| 97 |
|
}); |
| 98 |
|
|
| 99 |
1 |
List<ObjectEditPane> objects = getObjectsOfClass(className); |
| 100 |
1 |
return objects.get(objects.size() - 1); |
| 101 |
|
} |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
@since |
| 105 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 106 |
0 |
public void removeAllObjects(String className)... |
| 107 |
|
{ |
| 108 |
0 |
List<WebElement> objectContainers = getDriver().findElementsWithoutWaiting( |
| 109 |
|
By.xpath("//div[starts-with(@id, '" + "xobject_" + className + "_')]")); |
| 110 |
|
|
| 111 |
0 |
List<WebElement> validElements = new ArrayList<WebElement>(); |
| 112 |
0 |
for (WebElement element : objectContainers) { |
| 113 |
0 |
String id = element.getAttribute("id"); |
| 114 |
0 |
if (!id.endsWith("_content") && !id.endsWith("_title")) { |
| 115 |
0 |
validElements.add(element); |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
0 |
for (WebElement element : validElements) { |
| 119 |
0 |
deleteObject(By.id(element.getAttribute("id"))); |
| 120 |
|
} |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 123 |
1 |
public void deleteObject(String className, int index)... |
| 124 |
|
{ |
| 125 |
1 |
deleteObject(By.id("xobject_" + className + "_" + index)); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
@since |
| 130 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 131 |
1 |
public void deleteObject(By objectLocator)... |
| 132 |
|
{ |
| 133 |
1 |
final WebElement objectContainer = getDriver().findElement(objectLocator); |
| 134 |
1 |
WebElement deleteLink = objectContainer.findElement(By.className("delete")); |
| 135 |
1 |
deleteLink.click(); |
| 136 |
|
|
| 137 |
|
|
| 138 |
1 |
getDriver().waitUntilElementIsVisible(By.className("xdialog-box-confirmation")); |
| 139 |
1 |
getDriver().findElement(By.cssSelector(".xdialog-box-confirmation input[value='Yes']")).click(); |
| 140 |
1 |
getDriver().waitUntilElementDisappears(objectLocator); |
| 141 |
|
} |
| 142 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 143 |
1 |
public void removeAllDeprecatedProperties()... |
| 144 |
|
{ |
| 145 |
1 |
getDriver().findElement(By.className("syncAllProperties")).click(); |
| 146 |
1 |
getDriver().waitUntilElementDisappears(By.className("deprecatedProperties")); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
|
|
| 150 |
|
@param |
| 151 |
|
@param |
| 152 |
|
@return |
| 153 |
|
|
| |
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 154 |
2 |
public boolean isPropertyDeprecated(String className, String propertyName)... |
| 155 |
|
{ |
| 156 |
2 |
WebElement xclass = getDriver().findElement(By.id("xclass_" + className)); |
| 157 |
2 |
List<WebElement> deprecatedPropertiesElements = xclass.findElements(By.className("deprecatedProperties")); |
| 158 |
2 |
if (deprecatedPropertiesElements.size() > 0) { |
| 159 |
2 |
String xpath = "//label[. = '" + propertyName + ":']"; |
| 160 |
2 |
return deprecatedPropertiesElements.get(0).findElements(By.xpath(xpath)).size() > 0; |
| 161 |
|
} |
| 162 |
0 |
return false; |
| 163 |
|
} |
| 164 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 165 |
18 |
private FormElement getForm()... |
| 166 |
|
{ |
| 167 |
18 |
if (this.form == null) { |
| 168 |
17 |
this.form = new FormElement(this.objectForm); |
| 169 |
|
} |
| 170 |
18 |
return this.form; |
| 171 |
|
} |
| 172 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 173 |
0 |
public String getURL(String space, String page)... |
| 174 |
|
{ |
| 175 |
0 |
return getUtil().getURL(space, page, "edit", "editor=object"); |
| 176 |
|
} |
| 177 |
|
|
| 178 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
| 179 |
33 |
public List<ObjectEditPane> getObjectsOfClass(String className)... |
| 180 |
|
{ |
| 181 |
33 |
List<WebElement> titles = |
| 182 |
|
getDriver().findElement(By.id("xclass_" + className)).findElements(By.className("xobject-title")); |
| 183 |
33 |
List<WebElement> elements = |
| 184 |
|
getDriver().findElement(By.id("xclass_" + className)).findElements(By.className("xobject-content")); |
| 185 |
33 |
List<ObjectEditPane> objects = new ArrayList<ObjectEditPane>(elements.size()); |
| 186 |
72 |
for (int i = 0; i < elements.size(); i++) { |
| 187 |
39 |
WebElement element = elements.get(i); |
| 188 |
|
|
| 189 |
39 |
if (!element.isDisplayed()) { |
| 190 |
7 |
titles.get(i).click(); |
| 191 |
|
} |
| 192 |
39 |
int objectNumber = Integer.parseInt(element.getAttribute("id").split("_")[2]); |
| 193 |
39 |
objects.add(new ObjectEditPane(element, className, objectNumber)); |
| 194 |
|
} |
| 195 |
33 |
return objects; |
| 196 |
|
} |
| 197 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 198 |
12 |
public boolean hasObject(String className) {... |
| 199 |
12 |
return !getDriver().findElementsWithoutWaiting(By.id("xclass_" + className)).isEmpty(); |
| 200 |
|
} |
| 201 |
|
} |