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

File EntityTreeElement.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

2
20
15
1
233
79
16
0.8
1.33
15
1.07

Classes

Class Line # Actions
EntityTreeElement 32 20 0% 16 37
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 actions possible on the XWiki Explorer Tree.
28    *
29    * @version $Id: 8df661e0f5597a6fd0d5de24023c99af44fbe075 $
30    * @since 5.1M1
31    */
 
32    public class EntityTreeElement extends BaseElement
33    {
34    /**
35    * The text input below the tree, used to search for entities.
36    */
37    @FindBy(xpath = "//div[@class = 'listGrid']/following-sibling::input")
38    private WebElement input;
39   
40    /**
41    * Waits for the node corresponding to the specified space to be present but not selected.
42    *
43    * @param spaceName the space name
44    * @return this
45    */
 
46  0 toggle public EntityTreeElement waitForSpace(String spaceName)
47    {
48  0 return waitForSpace(spaceName, false);
49    }
50   
51    /**
52    * Waits for the node corresponding to the specified space to be present.
53    *
54    * @param spaceName the space name
55    * @param selected {@code true} if the space node should be selected, {@code false} otherwise
56    * @return this
57    */
 
58  0 toggle public EntityTreeElement waitForSpace(String spaceName, boolean selected)
59    {
60  0 return waitForNodeWithHintAndLabel("Located in xwiki \u00BB " + spaceName, spaceName, selected);
61    }
62   
63    /**
64    * @param spaceName the space name
65    * @return {@code true} if the node corresponding to the specified space is present (selected or not), {@code false}
66    * otherwise
67    */
 
68  0 toggle public boolean hasSpace(String spaceName)
69    {
70  0 return hasNodeWithHintAndLabel("Located in xwiki \u00BB " + spaceName, spaceName);
71    }
72   
73    /**
74    * Waits for the node corresponding to the specified page to be present but not selected. We assume the page title
75    * equals the page name.
76    *
77    * @param spaceName the space containing the page
78    * @param pageName the page name
79    * @return this
80    */
 
81  0 toggle public EntityTreeElement waitForPage(String spaceName, String pageName)
82    {
83  0 return waitForPage(spaceName, pageName, false);
84    }
85   
86    /**
87    * Waits for the node corresponding to the specified page to be present but not selected.
88    *
89    * @param spaceName the space containing the page
90    * @param pageName the page name (used as the node tool tip)
91    * @param pageTitle the page title (used as the node label)
92    * @return this
93    */
 
94  0 toggle public EntityTreeElement waitForPage(String spaceName, String pageName, String pageTitle)
95    {
96  0 return waitForPage(spaceName, pageName, pageTitle, false);
97    }
98   
99    /**
100    * Waits for the node corresponding to the specified page to be present. We assume the page title equals the page
101    * name.
102    *
103    * @param spaceName the space containing the page
104    * @param pageName the page name
105    * @param selected {@code true} if the page node should be selected, {@code false} otherwise
106    * @return this
107    */
 
108  0 toggle public EntityTreeElement waitForPage(String spaceName, String pageName, boolean selected)
109    {
110  0 return waitForPage(spaceName, pageName, pageName, selected);
111    }
112   
113    /**
114    * Waits for the node corresponding to the specified page to be present.
115    *
116    * @param spaceName the space containing the page
117    * @param pageName the page name (used as the node hint)
118    * @param pageTitle the page title (used as the node label)
119    * @param selected {@code true} if the page node should be selected, {@code false} otherwise
120    * @return this
121    */
 
122  0 toggle public EntityTreeElement waitForPage(String spaceName, String pageName, String pageTitle, boolean selected)
123    {
124  0 return waitForNodeWithHintAndLabel(String.format("Located in xwiki \u00BB %s \u00BB %s", spaceName, pageName),
125    pageTitle, selected);
126    }
127   
128    /**
129    * @param spaceName the space containing the page
130    * @param pageName the page name
131    * @return {@code true} if the specified page node is present, selected or not, {@code false} otherwise; we assume
132    * the page title equals the page name
133    */
 
134  0 toggle public boolean hasPage(String spaceName, String pageName)
135    {
136  0 return hasPage(spaceName, pageName, pageName);
137    }
138   
139    /**
140    * @param spaceName the space containing the page
141    * @param pageName the page name (used as the node hint)
142    * @param pageTitle the page title (used as the node label)
143    * @return {@code true} if the specified page node is present, selected or not, {@code false} otherwise
144    */
 
145  0 toggle public boolean hasPage(String spaceName, String pageName, String pageTitle)
146    {
147  0 return hasNodeWithHintAndLabel(String.format("Located in xwiki \u00BB %s \u00BB %s", spaceName, pageName),
148    pageTitle);
149    }
150   
151    /**
152    * Waits for the node corresponding to the specified attachments to be present but not selected.
153    *
154    * @param spaceName the space containing the page
155    * @param pageName the page that holds the attachment
156    * @param fileName the attachment file name
157    * @return this
158    */
 
159  0 toggle public EntityTreeElement waitForAttachment(String spaceName, String pageName, String fileName)
160    {
161  0 return waitForAttachment(spaceName, pageName, fileName, false);
162    }
163   
164    /**
165    * Waits for the node corresponding to the specified attachment to be present.
166    *
167    * @param spaceName the space containing the page
168    * @param pageName the page that holds the attachment
169    * @param fileName the attachment file name
170    * @param selected {@code true} if the attachment node should be selected, {@code false} otherwise
171    * @return this
172    */
 
173  0 toggle public EntityTreeElement waitForAttachment(String spaceName, String pageName, String fileName, boolean selected)
174    {
175  0 return waitForNodeWithHintAndLabel(String.format("Attached to xwiki \u00BB %s \u00BB %s", spaceName, pageName),
176    fileName, selected);
177    }
178   
179    /**
180    * @param spaceName the space containing the page
181    * @param pageName the page that holds the attachment
182    * @param fileName the attachment file name
183    * @return {@code true} if the specified attachment node is present, selected or not, {@code false} otherwise
184    */
 
185  0 toggle public boolean hasAttachment(String spaceName, String pageName, String fileName)
186    {
187  0 return hasNodeWithHintAndLabel(String.format("Attached to xwiki \u00BB %s \u00BB %s", spaceName, pageName),
188    fileName);
189    }
190   
191    /**
192    * Types the given text in the input box below the tree. As a result the tree will lookup an entity among its nodes
193    * (e.g. page, attachment) that matches the given reference.
194    *
195    * @param entityReference the text to be typed in the input box below the tree, usually an entity reference
196    */
 
197  0 toggle public void lookupEntity(String entityReference)
198    {
199  0 input.clear();
200  0 input.sendKeys(entityReference);
201    }
202   
203    /**
204    * Waits for the node with the specified hint and label to be present.
205    *
206    * @param hint the tool tip of the node to wait for
207    * @param label the label of the node to wait for
208    * @param selected whether the node should be selected or not
209    */
 
210  0 toggle private EntityTreeElement waitForNodeWithHintAndLabel(String hint, String label, boolean selected)
211    {
212  0 String className = selected ? "treeCellSelected" : "treeCell";
213  0 String xpath =
214    String.format("//td[contains(@class, '%s')]//*[@title = '%s' and . = '%s']", className, hint, label);
215  0 getDriver().waitUntilElementIsVisible(By.xpath(xpath));
216  0 return this;
217    }
218   
219    /**
220    * Checks if the node with the specified hint and label is present.
221    *
222    * @param hint the tool tip of the node to look for
223    * @param label the label of the node to look for
224    * @return {@code true} if the specified node is present, {@code false} otherwise
225    */
 
226  0 toggle private boolean hasNodeWithHintAndLabel(String hint, String label)
227    {
228  0 String format = "//td[starts-with(@class, 'treeCell')]//*[@title = '%s' and . = '%s']";
229    // Note: make sure to use findElementsWithoutWaiting() to speed up tests. Tests need to call waitFor*() APIs
230    // beforehand to ensure elements are visible in the tree.
231  0 return getDriver().findElementsWithoutWaiting(By.xpath(String.format(format, hint, label))).size() == 1;
232    }
233    }