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

File ViewPage.java

 

Coverage histogram

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

Code metrics

6
37
17
1
205
118
21
0.57
2.18
17
1.24

Classes

Class Line # Actions
ViewPage 40 37 0% 21 9
0.8585%
 

Contributing tests

This file is covered by 64 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.List;
23    import java.util.regex.Pattern;
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.model.reference.DocumentReference;
31    import org.xwiki.model.reference.EntityReference;
32    import org.xwiki.test.ui.po.editor.WYSIWYGEditPage;
33   
34    /**
35    * Represents the common actions possible on all Pages when using the "view" action.
36    *
37    * @version $Id: 9b0ea6e2bf673d4073f0f31767e73c4fd0e6eeff $
38    * @since 3.2M3
39    */
 
40    public class ViewPage extends BasePage
41    {
42    @FindBy(id = "xwikicontent")
43    private WebElement content;
44   
45    @FindBy(id = "hierarchy")
46    private WebElement breadcrumbElement;
47   
48    private BreadcrumbElement breadcrumb;
49   
50    /**
51    * Opens the comments tab.
52    *
53    * @return element for controlling the comments tab
54    */
 
55  15 toggle public CommentsTab openCommentsDocExtraPane()
56    {
57  15 getDriver().findElement(By.id("Commentslink")).click();
58  15 waitForDocExtraPaneActive("comments");
59  15 return new CommentsTab();
60    }
61   
 
62  11 toggle public HistoryPane openHistoryDocExtraPane()
63    {
64  11 getDriver().findElement(By.id("Historylink")).click();
65  11 waitForDocExtraPaneActive("history");
66  11 return new HistoryPane();
67    }
68   
 
69  6 toggle public AttachmentsPane openAttachmentsDocExtraPane()
70    {
71  6 getDriver().findElement(By.id("Attachmentslink")).click();
72  6 waitForDocExtraPaneActive("attachments");
73  6 return new AttachmentsPane();
74    }
75   
76    /** @return does this page exist. */
 
77  20 toggle public boolean exists()
78    {
79  20 List<WebElement> messages = getDriver().findElementsWithoutWaiting(By.className("xwikimessage"));
80  20 for (WebElement message : messages) {
81  14 if (message.getText().contains("The requested page could not be found.")
82    || message.getText().contains("The page has been deleted.")) {
83  14 return false;
84    }
85    }
86  6 return true;
87    }
88   
89    /**
90    * @return the page's main content as text (no HTML)
91    */
 
92  91 toggle public String getContent()
93    {
94  91 return this.content.getText();
95    }
96   
 
97  7 toggle public WYSIWYGEditPage editSection(int sectionNumber)
98    {
99  7 By sectionBy = By.xpath("//span[contains(@class, 'edit_section')][" + sectionNumber + "]/a");
100   
101    // Since Section Edit links are generated by JS (for XWiki Syntax 2.0) after the page has loaded make sure
102    // we wait for them.
103  7 getDriver().waitUntilElementIsVisible(sectionBy);
104   
105  7 getDriver().findElement(sectionBy).click();
106  7 return new WYSIWYGEditPage();
107    }
108   
109    /**
110    * Clicks on a wanted link in the page.
111    */
 
112  0 toggle public void clickWantedLink(String spaceName, String pageName, boolean waitForTemplateDisplay)
113    {
114  0 clickWantedLink(new DocumentReference("xwiki", spaceName, pageName), waitForTemplateDisplay);
115    }
116   
117    /**
118    * Clicks on a wanted link in the page.
119    *
120    * @since 7.2M2
121    */
 
122  1 toggle public void clickWantedLink(EntityReference reference, boolean waitForTemplateDisplay)
123    {
124  1 WebElement brokenLink = getDriver().findElement(
125    By.xpath("//span[@class='wikicreatelink']/a[contains(@href,'/create/" + getUtil().getURLFragment(reference)
126    + "')]"));
127  1 brokenLink.click();
128  1 if (waitForTemplateDisplay) {
129    // Ensure that the template choice popup is displayed. Since this is done using JS we need to wait till
130    // it's displayed. For that we wait on the Create button since that would mean the template radio buttons
131    // will all have been displayed.
132  1 getDriver().waitUntilElementIsVisible(By.xpath("//div[@class='modal-popup']//input[@type='submit']"));
133    }
134    }
135   
 
136  44 toggle public BreadcrumbElement getBreadcrumb()
137    {
138  44 if (this.breadcrumb == null) {
139  40 this.breadcrumb = new BreadcrumbElement(this.breadcrumbElement);
140    }
141  44 return this.breadcrumb;
142    }
143   
 
144  6 toggle public String getBreadcrumbContent()
145    {
146  6 return getBreadcrumb().getPathAsString();
147    }
148   
 
149  7 toggle public boolean hasBreadcrumbContent(String breadcrumbItem, boolean isCurrent)
150    {
151  7 return hasBreadcrumbContent(breadcrumbItem, isCurrent, true);
152    }
153   
 
154  10 toggle public boolean hasBreadcrumbContent(String breadcrumbItem, boolean isCurrent, boolean withLink)
155    {
156  10 return getBreadcrumb().hasPathElement(breadcrumbItem, isCurrent, withLink);
157    }
158   
159    /**
160    * Clicks on the breadcrumb link with the given text.
161    *
162    * @param linkText the link text
163    * @return the target of the breadcrumb link
164    */
 
165  12 toggle public ViewPage clickBreadcrumbLink(String linkText)
166    {
167  12 getBreadcrumb().clickPathElement(linkText);
168   
169  12 return new ViewPage();
170    }
171   
 
172  1 toggle public boolean isInlinePage()
173    {
174  1 return getDriver().findElements(By.xpath("//form[@id = 'inline']")).size() > 0;
175    }
176   
177    /**
178    * @param paneId valid values: "history", "comments", etc
179    */
 
180  42 toggle public void waitForDocExtraPaneActive(String paneId)
181    {
182  42 getDriver().waitUntilElementIsVisible(By.id(paneId + "content"));
183    }
184   
185    /**
186    * Waits until the page has the passed content by refreshing the page
187    *
188    * @param expectedValue the content value to wait for (in regex format)
189    * @since 4.0M1
190    */
 
191  0 toggle public void waitUntilContent(final String expectedValue)
192    {
193  0 getDriver().waitUntilCondition(new ExpectedCondition<Boolean>()
194    {
195    private Pattern pattern = Pattern.compile(expectedValue, Pattern.DOTALL);
196   
 
197  0 toggle @Override
198    public Boolean apply(WebDriver driver)
199    {
200  0 driver.navigate().refresh();
201  0 return Boolean.valueOf(pattern.matcher(getContent()).matches());
202    }
203    });
204    }
205    }