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

File CommentsTab.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

4
40
15
1
176
111
17
0.43
2.67
15
1.13

Classes

Class Line # Actions
CommentsTab 34 40 0% 17 13
0.77966178%
 

Contributing tests

This file is covered by 8 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.WebElement;
26    import org.openqa.selenium.support.FindBy;
27   
28    /**
29    * Page Object for Comments Tab.
30    *
31    * @version $Id: 40feaa615733e9040ad881ba9dd5f656164f6fd3 $
32    * @since 3.2M3
33    */
 
34    public class CommentsTab extends BaseElement
35    {
36    @FindBy(xpath = "//fieldset[@id='commentform']/label/span")
37    private WebElement commentAuthor;
38   
39    @FindBy(id = "XWiki.XWikiComments_author")
40    private WebElement anonymousCommentAuthor;
41   
42    private ConfirmationModal confirmDelete;
43   
44    private List<WebElement> commentsList;
45   
 
46  0 toggle public String getCurrentAuthor()
47    {
48  0 return this.commentAuthor.getAttribute("value");
49    }
50   
 
51  3 toggle public boolean isCommentFormShown()
52    {
53  3 WebElement commentForm = getDriver().findElement(
54    By.xpath("//form[@id='AddComment']/fieldset[@id='commentform']"));
55  3 return commentForm.isDisplayed();
56    }
57   
 
58  0 toggle public void setAnonymousCommentAuthor(String author)
59    {
60  0 this.anonymousCommentAuthor.clear();
61  0 this.anonymousCommentAuthor.sendKeys(author);
62    }
63   
 
64  18 toggle public int getCommentID(String content)
65    {
66  18 this.commentsList = getDriver().findElementsWithoutWaiting(By.className("xwikicomment"));
67   
68  20 for (int i = 0; i < this.commentsList.size(); i++) {
69  19 if (this.commentsList.get(i).findElement(By.className("commentcontent")).getText().equals(content)) {
70  17 return Integer
71    .parseInt(this.commentsList.get(i).getAttribute("id").substring("xwikicomment_".length()));
72    }
73    }
74  1 return -1;
75    }
76   
77    /**
78    * @return the form used to add a new comment
79    */
 
80  11 toggle public CommentForm getAddCommentForm()
81    {
82  11 return new CommentForm(By.id("AddComment"));
83    }
84   
 
85  7 toggle public int postComment(String content, boolean wait)
86    {
87  7 CommentForm addCommentForm = getAddCommentForm();
88  7 addCommentForm.getContentField().sendKeys(content);
89  7 addCommentForm.clickSubmit(wait);
90  7 return this.getCommentID(content);
91    }
92   
 
93  0 toggle public int postCommentAsGuest(String content, String author, boolean wait)
94    {
95  0 CommentForm addCommentForm = getAddCommentForm();
96  0 addCommentForm.getContentField().sendKeys(content);
97  0 this.setAnonymousCommentAuthor(author);
98  0 addCommentForm.clickSubmit(wait);
99  0 return this.getCommentID(content);
100    }
101   
 
102  3 toggle public void deleteCommentByID(int id)
103    {
104  3 getDriver().findElement(By.xpath("//div[@id='xwikicomment_" + id
105    + "']//a[contains(@class, 'delete')]")).click();
106  3 this.confirmDelete = new ConfirmationModal();
107  3 this.confirmDelete.clickOk();
108  3 getDriver().waitUntilElementIsVisible(
109    By.xpath("//div[contains(@class,'xnotification-done') and text()='Comment deleted']"));
110  3 getDriver().findElement(By.xpath("//div[contains(@class,'xnotification-done') and text()='Comment deleted']"))
111    .click();
112    }
113   
114    /**
115    * Clicks on the reply icon near the specified comment.
116    *
117    * @param id identifies the comment to reply to
118    * @return the form used to reply
119    */
 
120  2 toggle public CommentForm replyToCommentByID(int id)
121    {
122  2 getDriver().findElementWithoutWaiting(By.xpath("//div[@id='xwikicomment_"
123    + id + "']//a[contains(@class, 'commentreply')]")).click();
124  2 return getAddCommentForm();
125    }
126   
 
127  2 toggle public void replyToCommentByID(int id, String replyContent)
128    {
129  2 CommentForm replyCommentForm = replyToCommentByID(id);
130  2 replyCommentForm.getContentField().sendKeys(replyContent);
131  2 replyCommentForm.clickSubmit();
132    }
133   
134    /**
135    * Clicks on the edit icon near the specified comment.
136    *
137    * @param id identifies the comment to be edited
138    * @return the form used to edit the comment
139    */
 
140  2 toggle public CommentForm editCommentByID(int id)
141    {
142  2 getDriver().findElementWithoutWaiting(By.xpath("//div[@id='xwikicomment_"
143    + id + "']//a[contains(@class, 'edit')]")).click();
144  2 getDriver().waitUntilElementIsVisible(By.id("XWiki.XWikiComments_" + id + "_comment"));
145  2 return new CommentForm(By.className("edit-xcomment"));
146    }
147   
 
148  2 toggle public void editCommentByID(int id, String content)
149    {
150  2 CommentForm editCommentForm = editCommentByID(id);
151  2 editCommentForm.getContentField().clear();
152  2 editCommentForm.getContentField().sendKeys(content);
153  2 editCommentForm.clickSubmit();
154    }
155   
 
156  3 toggle public String getCommentAuthorByID(int id)
157    {
158  3 return getDriver().findElementWithoutWaiting(By.xpath("//div[@id='xwikicomment_"
159    + id + "']//span[@class='commentauthor']")).getText();
160    }
161   
 
162  4 toggle public String getCommentContentByID(int id)
163    {
164  4 return getDriver().findElementWithoutWaiting(By.xpath("//div[@id='xwikicomment_"
165    + id + "']//div[@class='commentcontent']")).getText();
166    }
167   
168    /**
169    * @since 3.2M3
170    */
 
171  0 toggle public boolean hasEditButtonForCommentByID(int commentId)
172    {
173  0 return getDriver().findElementsWithoutWaiting(By.xpath("//div[@id='xwikicomment_"
174    + commentId + "']//a[contains(@class, 'edit')]")).size() > 0;
175    }
176    }