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

File AttachmentsPane.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

2
29
15
1
182
111
17
0.59
1.93
15
1.13

Classes

Class Line # Actions
AttachmentsPane 35 29 0% 17 25
0.4565217545.7%
 

Contributing tests

This file is covered by 4 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 Attachment Pane at the bottom of a page.
31    *
32    * @version $Id: d7e826a7dc892d5e1b1d88aaca8f28eab9885047 $
33    * @since 3.2M3
34    */
 
35    public class AttachmentsPane extends BaseElement
36    {
37    @FindBy(id = "Attachmentspane")
38    private WebElement pane;
39   
40    @FindBy(xpath = "//input[@value='Add another file']")
41    private WebElement addAnotherFile;
42   
43    /**
44    * Fills the URL with the specified file path.
45    *
46    * @param filePath the path to the file to upload in URL form (the file *must* exist in the target directory).
47    */
 
48  8 toggle public void setFileToUpload(final String filePath)
49    {
50  8 final List<WebElement> inputs = this.pane.findElements(By.className("uploadFileInput"));
51  8 inputs.get(inputs.size() - 1).sendKeys(filePath);
52    }
53   
 
54  7 toggle public void waitForUploadToFinish(String fileName)
55    {
56  7 waitForNotificationSuccessMessage("Attachment uploaded: " + fileName);
57    }
58   
 
59  4 toggle public void clickHideProgress()
60    {
61  4 this.pane.findElement(By.xpath("//a[text()='Hide upload status']")).click();
62    }
63   
64    /**
65    * Adds another input field for attaching a file.
66    */
 
67  0 toggle public void addAnotherFile()
68    {
69  0 this.addAnotherFile.click();
70    }
71   
 
72  0 toggle public void clickAttachFiles()
73    {
74  0 this.pane.findElement(By.xpath("//form[@id='AddAttachment']//input[@class='button' and @type='submit' and "
75    + "@value='Attach']")).click();
76    }
77   
78    /**
79    * @since 3.2M3
80    */
 
81  2 toggle public WebElement getAttachmentLink(String attachmentName)
82    {
83  2 return getDriver().findElement(
84    By.xpath("//div[@id='_attachments']//a[@title = 'Download this attachment' and contains(@href, '"
85    + attachmentName + "')]"));
86    }
87   
88    /**
89    * Deletes the corresponding file name.
90    *
91    * @param attachmentName the name of the attachment to be deleted
92    */
 
93  1 toggle public void deleteAttachmentByFileByName(String attachmentName)
94    {
95  1 getDriver().findElement(
96    By.xpath("//div[@id='attachmentscontent']//a[text()='" + attachmentName
97    + "']/../../div[contains(@class, 'xwikibuttonlinks')]/a[contains(@class,'deletelink')]")).click();
98  1 getDriver().findElement(By.xpath("//*[@class='xdialog-modal-container']//input[@value='Yes']")).click();
99  1 getDriver().waitUntilElementDisappears(By
100    .xpath("//*[@class='xdialog-modal-container']/*[contains(@class, 'xdialog-box-confirmation')]"));
101  1 getDriver().waitUntilElementDisappears(By.xpath("//div[@id='attachmentscontent']//a[text()='"
102    + attachmentName + "']"));
103  1 getDriver().waitUntilElementIsVisible(By.xpath("//div[@id='Attachmentspane']"));
104    }
105   
106    /**
107    * Deletes the first attachment.
108    */
 
109  0 toggle public void deleteFirstAttachment()
110    {
111  0 String tmp = getDriver().findElement(
112    By.xpath("//div[@id='_attachments']/*[1]/div[@class='information']/span[@class='name']")).getText();
113  0 getDriver().findElement(
114    By.xpath("//div[@id='attachmentscontent']//a[text()='" + tmp + "']/../../span[2]/a[@class='deletelink']"))
115    .click();
116   
117  0 getDriver().findElement(By.xpath("//*[@class='xdialog-modal-container']//input[@value='Yes']")).click();
118  0 getDriver().waitUntilElementDisappears(By
119    .xpath("//*[@class='xdialog-modal-container']/*[contains(@class, 'xdialog-box-confirmation')]"));
120  0 getDriver().waitUntilElementDisappears(By.xpath("//div[@id='attachmentscontent']//a[text()='" + tmp
121    + "']/../../span[2]/a[@class='deletelink']"));
122    }
123   
124    /**
125    * @return the number of attachments in this document.
126    */
 
127  0 toggle public int getNumberOfAttachments()
128    {
129  0 By countLocator = By.cssSelector("#Attachmentstab .itemCount");
130  0 return Integer.parseInt(getDriver().findElement(countLocator).getText().replaceAll("[()]", ""));
131    }
132   
133    /**
134    * Deletes ALL the attached files
135    */
 
136  0 toggle public void deleteAllAttachments()
137    {
138  0 while (this.getNumberOfAttachments() > 0) {
139  0 this.deleteFirstAttachment();
140    }
141    }
142   
 
143  0 toggle public String getUploaderOfAttachment(String attachmentName)
144    {
145  0 return getDriver().findElement(
146    By.xpath("//div[@id='attachmentscontent']//a[text()='" + attachmentName
147    + "']/../../div[@class='meta']/span[@class='publisher']/span[@class='wikilink']")).toString();
148    }
149   
 
150  4 toggle public String getLatestVersionOfAttachment(String attachmentName)
151    {
152  4 return getDriver().findElement(
153    By.xpath("//div[@id='attachmentscontent']//a[text()= '" + attachmentName
154    + "']/../../span[@class='version']/a")).getText();
155    }
156   
 
157  0 toggle public String getSizeOfAttachment(String attachmentName)
158    {
159  0 return getDriver().findElement(
160    By.xpath("//div[@id='attachmentscontent']//a[text()='" + attachmentName
161    + "']/../../div[@class='meta']/span[@class='size']")).toString().replaceAll("[()]", "");
162   
163    }
164   
 
165  0 toggle public String getDateOfLastUpload(String attachmentName)
166    {
167  0 return getDriver().findElement(
168    By.xpath("//div[@id='attachmentscontent']//a[text()='" + attachmentName
169    + "']/../../div[@class='meta']/span[@class='date']")).toString().replaceFirst("on", "");
170    }
171   
 
172  1 toggle public boolean attachmentExistsByFileName(String attachmentName)
173    {
174  1 try {
175  1 getDriver().findElement(
176    By.xpath("//a[@title = 'Download this attachment' and . = '" + attachmentName + "']"));
177    } catch (NoSuchElementException e) {
178  0 return false;
179    }
180  1 return true;
181    }
182    }