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

File HistoryPane.java

 

Coverage histogram

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

Code metrics

2
32
9
1
151
84
13
0.41
3.56
9
1.44

Classes

Class Line # Actions
HistoryPane 35 32 0% 13 2
0.9534883595.3%
 

Contributing tests

This file is covered by 10 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   
24    import org.openqa.selenium.By;
25    import org.openqa.selenium.NoSuchElementException;
26    import org.openqa.selenium.WebElement;
27    import org.openqa.selenium.support.FindBy;
28   
29    /**
30    * Represents the actions possible on the History Pane at the bottom of a page.
31    *
32    * @version $Id: 307a80415001dcfa53985fe417bdb38cc1b9e486 $
33    * @since 3.2M3
34    */
 
35    public class HistoryPane extends BaseElement
36    {
37    @FindBy(id = "historycontent")
38    private WebElement pane;
39   
 
40  1 toggle public boolean hasVersionWithSummary(String summary)
41    {
42  1 List<WebElement> tableEntries = pane.findElements(By.xpath(".//table/tbody/tr"));
43  1 By commentVersionXPath;
44  1 try {
45  1 pane.findElement(By.xpath(".//tr[2]/td/input"));
46  1 commentVersionXPath = By.xpath(".//td[6]");
47    } catch (NoSuchElementException e) {
48  0 commentVersionXPath = By.xpath(".//td[4]");
49    }
50  1 for (WebElement tableEntry : tableEntries) {
51  2 try {
52  2 WebElement cell = tableEntry.findElement(commentVersionXPath);
53  2 if (cell.getText().trim().contentEquals(summary)) {
54  1 return true;
55    }
56    } catch (NoSuchElementException e) {
57    // Ignore, better luck next time.
58    }
59    }
60  0 return false;
61    }
62   
 
63  7 toggle public String getCurrentVersion()
64    {
65  7 return getCurrentItemInTable("td[3]/a", "td[1]/a");
66    }
67   
 
68  3 toggle public String getCurrentVersionComment()
69    {
70  3 return getCurrentItemInTable("td[6]", "td[4]");
71    }
72   
 
73  4 toggle public String getCurrentAuthor()
74    {
75  4 return getCurrentItemInTable("td[4]", "td[2]");
76    }
77   
 
78  14 toggle private String getCurrentItemInTable(String xpathFragment1, String xpathFragment2)
79    {
80  14 try {
81    // Try to find a radio button. This will mean there are several revisions in the table
82    // and we'll find the version written down in the 3rd column
83  14 getDriver().findElementWithoutWaiting(this.pane, By.xpath(".//tr[2]/td/input"));
84  8 return getDriver().findElementWithoutWaiting(this.pane,
85    By.xpath(".//*[contains(@class, 'currentversion')]/" + xpathFragment1)).getText();
86    } catch (NoSuchElementException e) {
87    // If we couldn't find the radio button, there is less columns displayed and the version will be
88    // in the first column
89  6 return getDriver().findElementWithoutWaiting(this.pane,
90    By.xpath(".//*[contains(@class, 'currentversion')]/" + xpathFragment2)).getText();
91    }
92    }
93   
94    /**
95    * IMPORTANT: this method isn't blocking and doesn't wait for the page to be loaded (after the confirmation popup
96    * has been accepted).
97    */
 
98  1 toggle public ViewPage rollbackToVersion(String version)
99    {
100  1 getDriver().makeConfirmDialogSilent(true);
101   
102  1 pane.findElement(
103    By.xpath(".//table//tr[contains(., '" + version
104    + "')]//td[@class='xwikibuttonlink']/a[contains(.,'Rollback')]")).click();
105   
106    // A new page is loaded after the dialog is accepted, thus we need to wait that it's loaded before returning
107    // as otherwise following actions may be performed on the current page and not on the new page.
108    // TODO: Find a generic way to test for this condition. Right now users of this method need to perform their
109    // own wait.
110   
111  1 return new ViewPage();
112    }
113   
 
114  1 toggle public HistoryPane deleteVersion(String version)
115    {
116  1 getDriver().makeConfirmDialogSilent(true);
117   
118  1 pane.findElement(
119    By.xpath(".//table//tr[contains(., '" + version
120    + "')]//td[@class='xwikibuttonlink']/a[contains(.,'Delete')]")).click();
121   
122  1 return new HistoryPane();
123    }
124   
125    /**
126    * Clicks on the 'Show Minor Edits' button.
127    *
128    * @return the new history pane that includes the minor edits
129    */
 
130  2 toggle public HistoryPane showMinorEdits()
131    {
132  2 getDriver().findElementWithoutWaiting(pane, By.name("viewminorversions")).click();
133  2 return new HistoryPane();
134    }
135   
136    /**
137    * Selects the specified document versions and clicks the button to compare them.
138    *
139    * @param fromVersion the from version
140    * @param toVersion the to version
141    * @return the page that shows the differences between the selected pages
142    */
 
143  2 toggle public ComparePage compare(String fromVersion, String toVersion)
144    {
145  2 String versionXPath = ".//input[@name = 'rev%s' and @value = '%s']";
146  2 getDriver().findElementWithoutWaiting(pane, By.xpath(String.format(versionXPath, 1, fromVersion))).click();
147  2 getDriver().findElementWithoutWaiting(pane, By.xpath(String.format(versionXPath, 2, toVersion))).click();
148  2 getDriver().findElementWithoutWaiting(pane, By.xpath(".//input[@accesskey = 'c']")).click();
149  2 return new ComparePage();
150    }
151    }