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

File BreadcrumbElement.java

 

Coverage histogram

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

Code metrics

4
20
7
1
101
57
9
0.45
2.86
7
1.29

Classes

Class Line # Actions
35 20 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 21 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 java.util.ArrayList;
23    import java.util.List;
24   
25    import org.apache.commons.lang.StringUtils;
26    import org.openqa.selenium.By;
27    import org.openqa.selenium.WebElement;
28   
29    /**
30    * Represents the page breadcrumb.
31    *
32    * @version $Id: 55945972d7f092b08ee81519a7bdee2b82fe05d2 $
33    * @since 7.2M3
34    */
 
35    public class BreadcrumbElement extends BaseElement
36    {
37    private WebElement container;
38   
 
39  61 toggle public BreadcrumbElement(WebElement container)
40    {
41  61 this.container = container;
42    }
43   
 
44  44 toggle public List<String> getPath()
45    {
46  44 List<WebElement> pathElements = getDriver().findElementsWithoutWaiting(this.container, By.tagName("li"));
47  44 List<String> path = new ArrayList<>();
48  44 for (WebElement pathElement : pathElements) {
49  166 path.add(pathElement.getText());
50    }
51  44 return path;
52    }
53   
 
54  32 toggle public String getPathAsString()
55    {
56  32 return StringUtils.join(getPath(), '/');
57    }
58   
 
59  17 toggle public void clickPathElement(String linkText)
60    {
61  17 this.container.findElement(By.linkText(linkText)).click();
62    }
63   
 
64  24 toggle public boolean hasPathElement(String text, boolean isCurrent, boolean withLink)
65    {
66  24 List<WebElement> result;
67  24 if (isCurrent) {
68  2 result = getDriver().findElementsWithoutWaiting(this.container,
69    By.xpath("li[contains(@class, 'active')]/a[. = '" + text + "']"));
70    } else {
71  22 if (withLink) {
72  21 result = getDriver().findElementsWithoutWaiting(this.container, By.xpath("//a[. = '" + text + "']"));
73    } else {
74    // if the user has not the right to see the parent, there is no link to the parent, only a <li> with the
75    // name of the document
76  1 result = getDriver().findElementsWithoutWaiting(this.container, By.xpath("//li[. = '" + text + "']"));
77    }
78    }
79  24 return result.size() > 0;
80    }
81   
 
82  5 toggle public void expand()
83    {
84    // Remember the id of the container so that we can retrieve it when it will be removed and re-inserted.
85  5 final String containerId = this.container.getAttribute("id");
86   
87  5 clickPathElement("…");
88   
89    // Expanding the breadcrumb remove the current container and replace it by an updated one (with the full
90    // hierarchy inside). So we wait until the container is re-inserted without any "ellipsis" item.
91  5 getDriver().waitUntilElementDisappears(By.cssSelector("#" + containerId + " .ellipsis"));
92   
93    // Update the internal reference
94  5 this.container = getDriver().findElementById(containerId);
95    }
96   
 
97  14 toggle public boolean canBeExpanded()
98    {
99  14 return hasPathElement("…", false, true);
100    }
101    }