1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.ui.po.editor

File ObjectEditPage.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
55
14
1
201
131
20
0.36
3.93
14
1.43

Classes

Class Line # Actions
ObjectEditPage 38 55 0% 20 15
0.810126681%
 

Contributing tests

This file is covered by 19 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Represents the common actions possible on all Pages when using the "edit" action with the "object" editor.
34    *
35    * @version $Id: f19c441ef6cf45d973a80fad690dd0bc33323e81 $
36    * @since 3.2M3
37    */
 
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    * Go to the passed page in object edit mode.
53    */
 
54  16 toggle 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   
 
60  18 toggle 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    // Make sure we wait for the element to appear since there's no page refresh.
69  18 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
70    {
 
71  36 toggle @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   
 
82  1 toggle 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    // Make sure we wait for the element to appear since there's no page refresh.
90  1 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
91    {
 
92  2 toggle @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 4.3M2
105    */
 
106  0 toggle public void removeAllObjects(String className)
107    {
108  0 List<WebElement> objectContainers = getDriver().findElementsWithoutWaiting(
109    By.xpath("//div[starts-with(@id, '" + "xobject_" + className + "_')]"));
110    // Exclude ids ending with _title and _content since we have 3 matches for each id...
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   
 
123  1 toggle public void deleteObject(String className, int index)
124    {
125  1 deleteObject(By.id("xobject_" + className + "_" + index));
126    }
127   
128    /**
129    * @since 4.3M2
130    */
 
131  1 toggle 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    // Expect a confirmation box
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   
 
143  1 toggle public void removeAllDeprecatedProperties()
144    {
145  1 getDriver().findElement(By.className("syncAllProperties")).click();
146  1 getDriver().waitUntilElementDisappears(By.className("deprecatedProperties"));
147    }
148   
149    /**
150    * @param className a class name
151    * @param propertyName a class field name
152    * @return {@code true} if the specified class field is listed as deprecated, {@code false} otherwise
153    */
 
154  2 toggle 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   
 
165  18 toggle 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   
 
173  0 toggle public String getURL(String space, String page)
174    {
175  0 return getUtil().getURL(space, page, "edit", "editor=object");
176    }
177   
178    /** className will look something like "XWiki.XWikiRights" */
 
179  33 toggle 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    // Make sure all forms are displayed otherwise we can't interact with them.
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   
 
198  12 toggle public boolean hasObject(String className) {
199  12 return !getDriver().findElementsWithoutWaiting(By.id("xclass_" + className)).isEmpty();
200    }
201    }