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

File InlinePage.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
29
14
1
206
98
18
0.62
2.07
14
1.29

Classes

Class Line # Actions
InlinePage 32 29 0% 18 2
0.960784396.1%
 

Contributing tests

This file is covered by 46 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;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.WebElement;
24    import org.openqa.selenium.support.FindBy;
25   
26    /**
27    * Represents the common actions possible on all Pages when using the "inline" action.
28    *
29    * @version $Id: 38a197dfcdaba87acba1668f1152f042d35a8b1c $
30    * @since 3.2M3
31    */
 
32    public class InlinePage extends ViewPage
33    {
34    /**
35    * The XPath that locates a form field.
36    */
37    private static final String FIELD_XPATH_FORMAT = "//*[substring(@name, string-length(@name) - %s - 2) = '_0_%s']";
38   
39    @FindBy(name = "action_preview")
40    private WebElement preview;
41   
42    @FindBy(name = "action_saveandcontinue")
43    private WebElement saveandcontinue;
44   
45    @FindBy(name = "action_save")
46    private WebElement save;
47   
48    @FindBy(name = "action_cancel")
49    private WebElement cancel;
50   
51    @FindBy(id = "inline")
52    private WebElement form;
53   
 
54  1 toggle public void clickPreview()
55    {
56  1 preview.click();
57    }
58   
 
59  11 toggle public void clickSaveAndContinue()
60    {
61  11 clickSaveAndContinue(true);
62    }
63   
64    /**
65    * Clicks on the Save and Continue button. Use this instead of {@link #clickSaveAndContinue()} when you want to wait
66    * for a different message (e.g. an error message).
67    *
68    * @param wait {@code true} to wait for the page to be saved, {@code false} otherwise
69    */
 
70  12 toggle public void clickSaveAndContinue(boolean wait)
71    {
72  12 getSaveAndContinueButton().click();
73   
74  12 if (wait) {
75    // Wait until the page is really saved.
76  11 waitForNotificationSuccessMessage("Saved");
77    }
78    }
79   
80    /**
81    * Use this method instead of {@link #clickSaveAndContinue()} and call {@link WebElement#click()} when you know that
82    * the next page is not a standard XWiki {@link InlinePage}.
83    *
84    * @return the save and continue button used to submit the form.
85    */
 
86  3 toggle public WebElement getSaveAndContinueButton()
87    {
88  3 return saveandcontinue;
89    }
90   
 
91  46 toggle public <T extends ViewPage> T clickSaveAndView()
92    {
93  46 clickSaveAndView(true);
94   
95  46 return createViewPage();
96    }
97   
98    /**
99    * Useful when the save and view operation could fail on the client side and a reload (the view part) might thus not
100    * take place.
101    *
102    * @param wait {@code true} to wait for the page to be saved and reloaded, {@code false} otherwise
103    * @since 7.4M2
104    */
 
105  46 toggle public void clickSaveAndView(boolean wait)
106    {
107  46 if (wait) {
108  46 getDriver().addPageNotYetReloadedMarker();
109    }
110   
111  46 this.getSaveAndViewButton().click();
112   
113  46 if (wait) {
114    // Since we might have a loading step between clicking Save&View and the view page actually loading
115    // (specifically when using templates that have child documents associated), we need to wait for the save to
116    // finish and for the redirect to occur.
117  46 getDriver().waitUntilPageIsReloaded();
118    }
119    }
120   
121    /**
122    * Use this method instead of {@link #clickSaveAndView()} and call {@link WebElement#click()} when you know that the
123    * next page is not a standard XWiki {@link InlinePage}.
124    *
125    * @return the save and view button used to submit the form.
126    */
 
127  25 toggle public WebElement getSaveAndViewButton()
128    {
129  25 return save;
130    }
131   
 
132  6 toggle public <T extends ViewPage> T clickCancel()
133    {
134  6 cancel.click();
135  6 return createViewPage();
136    }
137   
138    /**
139    * Can be overridden to return extended {@link ViewPage}.
140    */
 
141  42 toggle protected <T extends ViewPage> T createViewPage()
142    {
143  42 return (T) new ViewPage();
144    }
145   
 
146  6 toggle @Override
147    public String getContent()
148    {
149  6 return form.getText();
150    }
151   
152    /**
153    * @return the form element
154    */
 
155  57 toggle public WebElement getForm()
156    {
157  57 return form;
158    }
159   
160    /**
161    * Retrieves the value of the specified form field
162    *
163    * @param fieldName the name of a form field
164    * @return the value of the specified form field
165    * @since 7.0RC1
166    */
 
167  7 toggle public String getValue(String fieldName)
168    {
169  7 String xpath = String.format(FIELD_XPATH_FORMAT, fieldName.length(), fieldName);
170  7 return new FormElement(getForm()).getFieldValue(By.xpath(xpath));
171    }
172   
173    /**
174    * Sets the value of the specified form field
175    *
176    * @param fieldName the name of a form field
177    * @param fieldValue the new value for the specified form field
178    * @since 7.0RC1
179    */
 
180  9 toggle public void setValue(String fieldName, String fieldValue)
181    {
182  9 String xpath = String.format(FIELD_XPATH_FORMAT, fieldName.length(), fieldName);
183  9 WebElement field = getForm().findElement(By.xpath(xpath));
184  9 if (field.getAttribute("name").equals(field.getAttribute("id"))) {
185  7 new FormElement(getForm()).setFieldValue(field, fieldValue);
186    } else {
187  2 xpath = String.format("//*[@name = '%s' and @value = '%s']", field.getAttribute("name"), fieldValue);
188  2 new FormElement(getForm()).setCheckBox(By.xpath(xpath), true);
189    }
190    }
191   
192    /**
193    * @since 7.4M2
194    */
 
195  113 toggle @Override
196    public void waitUntilPageJSIsLoaded()
197    {
198  113 super.waitUntilPageJSIsLoaded();
199   
200    // Actionbuttons javascript for saving the page.
201  113 getDriver().waitUntilJavascriptCondition(
202    "return XWiki.actionButtons != undefined && " + "XWiki.actionButtons.EditActions != undefined && "
203    + "XWiki.actionButtons.AjaxSaveAndContinue != undefined");
204    }
205   
206    }