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

File EditPage.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

8
45
21
2
329
166
25
0.56
2.14
10.5
1.19

Classes

Class Line # Actions
EditPage 43 40 0% 21 22
0.661538566.2%
EditPage.Editor 81 5 0% 4 2
0.777777877.8%
 

Contributing tests

This file is covered by 60 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.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    * Represents the common actions possible on all Pages when using the "edit" action.
39    *
40    * @version $Id: b692f12b6bf71e57edb805ff6c3fbe92f9b7e75d $
41    * @since 3.2M3
42    */
 
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    * The top floating edit menu bar.
68    */
69    @FindBy(id = "editmenu")
70    private WebElement editMenuBar;
71   
72    /**
73    * The entry on the edit menu bar that displays the current editor and allows us to switch the editor.
74    */
75    @FindBy(id = "tmCurrentEditor")
76    private WebElement currentEditorMenu;
77   
78    /**
79    * Enumerates the available editors.
80    */
 
81    public enum Editor
82    {
83    WYSIWYG("WYSIWYG"),
84    WIKI("Wiki"),
85    RIGHTS("Access Rights"),
86    OBJECT("Objects"),
87    CLASS("Class");
88   
89    /**
90    * The mapping between pretty names and editors.
91    */
92    private static final Map<String, Editor> BY_PRETTY_NAME = new HashMap<String, Editor>();
93   
 
94  1 toggle static {
95    // NOTE: We cannot refer to a static enum field within the initializer because enums are initialized before
96    // any static initializers are run so we are forced to use a static block to build the map.
97  1 for (Editor editor : values()) {
98  5 BY_PRETTY_NAME.put(editor.getPrettyName(), editor);
99    }
100    }
101   
102    /**
103    * The string used to display the name of the editor on the edit menu.
104    */
105    private final String prettyName;
106   
107    /**
108    * Defines a new editor with the given pretty name.
109    *
110    * @param prettyName the string used to display the name of the editor on the edit menu
111    */
 
112  5 toggle Editor(String prettyName)
113    {
114  5 this.prettyName = prettyName;
115    }
116   
117    /**
118    * @return the string used to display the name of the editor on the edit menu
119    */
 
120  5 toggle public String getPrettyName()
121    {
122  5 return this.prettyName;
123    }
124   
125    /**
126    * @param prettyName the string used to display the name of the editor on the edit menu
127    * @return the editor corresponding to the given pretty name, {@code null} if no editor matches the given pretty
128    * name
129    */
 
130  0 toggle public static Editor byPrettyName(String prettyName)
131    {
132  0 return BY_PRETTY_NAME.get(prettyName);
133    }
134    }
135   
 
136  17 toggle public void clickSaveAndContinue()
137    {
138  17 this.clickSaveAndContinue(true);
139    }
140   
141    /**
142    * Clicks on the Save and Continue button. Use this instead of {@link #clickSaveAndContinue()} when you want to wait
143    * for a different message (e.g. an error message).
144    *
145    * @param wait {@code true} to wait for the page to be saved, {@code false} otherwise
146    */
 
147  18 toggle public void clickSaveAndContinue(boolean wait)
148    {
149  18 this.getSaveAndContinueButton().click();
150   
151  18 if (wait) {
152    // Wait until the page is really saved.
153  17 waitForNotificationSuccessMessage("Saved");
154    }
155    }
156   
157    /**
158    * Use this method instead of {@link #clickSaveAndContinue()} and call {@link WebElement#click()} when you know that
159    * the next page is not a standard XWiki {@link InlinePage}.
160    *
161    * @return the save and continue button used to submit the form.
162    */
 
163  18 toggle public WebElement getSaveAndContinueButton()
164    {
165  18 return saveandcontinue;
166    }
167   
 
168  89 toggle public <T extends ViewPage> T clickSaveAndView()
169    {
170  89 clickSaveAndView(true);
171   
172  89 return (T) new ViewPage();
173    }
174   
175    /**
176    * Useful when the save and view operation could fail on the client side and a reload (the view part) might thus not
177    * take place.
178    *
179    * @param wait if we should wait for the page to be reloaded
180    * @since 7.4M2
181    */
 
182  89 toggle 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    // Since we might have a loading step between clicking Save&View and the view page actually loading
192    // (specifically when using templates that have child documents associated), we need to wait for the save to
193    // finish and for the redirect to occur.
194  89 getDriver().waitUntilPageIsReloaded();
195    }
196    }
197   
198    /**
199    * Use this method instead of {@link #clickSaveAndView()} and call {@link WebElement#click()} when you know that the
200    * next page is not a standard XWiki {@link InlinePage}.
201    *
202    * @return the save and view button used to submit the form.
203    */
 
204  74 toggle public WebElement getSaveAndViewButton()
205    {
206  74 return save;
207    }
208   
 
209  8 toggle public ViewPage clickCancel()
210    {
211  8 this.cancel.click();
212  8 return new ViewPage();
213    }
214   
215    /**
216    * @return the editor being used on this page
217    */
 
218  1 toggle 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 the syntax if of the page
233    * @since 3.2M3
234    */
 
235  0 toggle public String getSyntaxId()
236    {
237  0 return this.syntaxIdSelect.getAttribute("value");
238    }
239   
240    /**
241    * @since 3.2M3
242    */
 
243  0 toggle public void setSyntaxId(String syntaxId)
244    {
245  0 Select select = new Select(this.syntaxIdSelect);
246  0 select.selectByValue(syntaxId);
247    }
248   
249    /**
250    * @return the value of the parent field.
251    * @since 7.2M2
252    */
 
253  2 toggle public String getParent()
254    {
255  2 return this.parentInput.getAttribute("value");
256    }
257   
258    /**
259    * @since 7.2M2
260    */
 
261  5 toggle @Override
262    public String getDocumentTitle()
263    {
264  5 return this.titleField.getAttribute("value");
265    }
266   
267    /**
268    * @since 7.4M2
269    */
 
270  179 toggle @Override
271    public void waitUntilPageJSIsLoaded()
272    {
273  179 super.waitUntilPageJSIsLoaded();
274   
275    // // Actionbuttons javascript for saving the page.
276  179 getDriver().waitUntilJavascriptCondition(
277    "return XWiki.actionButtons != undefined && " + "XWiki.actionButtons.EditActions != undefined && "
278    + "XWiki.actionButtons.AjaxSaveAndContinue != undefined");
279    }
280   
 
281  0 toggle 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 a list of the locales already translated for this document
293    * @since 9.0RC1
294    */
 
295  0 toggle 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 a list of the supported locales not yet translated for this document
305    * @since 9.0RC1
306    */
 
307  0 toggle 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 locale the locale to translate to
317    * @return the target locale edit page
318    * @since 9.0RC1
319    */
 
320  0 toggle 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    }