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

File AnnotatableViewPage.java

 

Coverage histogram

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

Code metrics

2
59
15
1
189
124
16
0.27
3.93
15
1.07

Classes

Class Line # Actions
AnnotatableViewPage 33 59 0% 16 12
0.8421052784.2%
 

Contributing tests

This file is covered by 2 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.annotation.test.po;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.JavascriptExecutor;
24    import org.openqa.selenium.Keys;
25    import org.openqa.selenium.WebElement;
26    import org.xwiki.test.ui.po.BaseElement;
27    import org.xwiki.test.ui.po.ViewPage;
28   
29    /**
30    * @since 4.2M1
31    * @version $Id: 0fb26b9ba5137a8c443784cc87e47380996bfe7e $
32    */
 
33    public class AnnotatableViewPage extends BaseElement
34    {
35    private static final String XWIKI_ANNOTATION_ADD_SUCCESS = "Annotation has been successfully added";
36   
37    private static final String XWIKI_ANNOTATION_DELETE_SUCCESS = "Annotation deleted";
38   
39    private static final String XWIKI_SYNTAX_1_WARNING =
40    "Annotations are not available for pages in XWiki/1.0 syntax.";
41   
42    private AnnotationsPane annotationsPane;
43   
44    private AnnotationsWindow annotationsWindow;
45   
46    private AnnotationsLabel annotationsLabel;
47   
48    private StringBuilder script;
49   
50    private ViewPage viewPage;
51   
 
52  2 toggle public AnnotatableViewPage(ViewPage viewPage)
53    {
54  2 this.viewPage = viewPage;
55   
56    /**
57    * Injection of this javascript function is used because the Selenium 2 API does not yet fully support advanced
58    * interactions with the mouse. This can't be yet achieved via Selenium 2 API. This function selects the text
59    * from the page (drag-over with mouse simulation)
60    */
61  2 script = new StringBuilder();
62  2 script.append("function findString (str) {\n");
63  2 script.append(" var strFound;\n");
64  2 script.append(" if (window.find) {\n");
65  2 script.append(" if (parseInt(navigator.appVersion)<4) return;\n");
66  2 script.append(" // CODE FOR BROWSERS THAT SUPPORT window.find\n");
67  2 script.append(" strFound = self.find(str);\n");
68  2 script.append(" if (strFound && self.getSelection && !self.getSelection().anchorNode) {\n");
69  2 script.append(" strFound = self.find(str);\n");
70  2 script.append(" }\n");
71  2 script.append(" if (!strFound) {\n");
72  2 script.append(" strFound = self.find(str,0,1);\n");
73  2 script.append(" while (self.find(str,0,1)) continue;\n");
74  2 script.append(" }\n");
75  2 script.append(" } else if (navigator.appName.indexOf(\"Microsoft\")!=-1) {\n");
76  2 script.append(" // EXPLORER-SPECIFIC CODE\n");
77  2 script.append(" if (TRange != null) {\n");
78  2 script.append(" TRange.collapse(false);\n");
79  2 script.append(" strFound = TRange.findText(str);\n");
80  2 script.append(" if (strFound) TRange.select();\n");
81  2 script.append(" }\n");
82  2 script.append(" if (TRange == null || strFound == 0) {\n");
83  2 script.append(" TRange = self.document.body.createTextRange();\n");
84  2 script.append(" strFound = TRange.findText(str);\n");
85  2 script.append(" if (strFound) TRange.select();\n");
86  2 script.append(" }\n");
87  2 script.append(" } else if (navigator.appName == \"Opera\") {\n");
88  2 script.append(" alert ('Opera browsers not supported, sorry...');\n");
89  2 script.append(" return;\n");
90  2 script.append(" }\n");
91  2 script.append(" if (!strFound) \n");
92  2 script.append(" return;\n");
93  2 script.append("}\n");
94  2 ((JavascriptExecutor) getDriver()).executeScript(script.toString());
95   
96  2 annotationsPane = new AnnotationsPane();
97  2 annotationsWindow = new AnnotationsWindow();
98  2 annotationsLabel = new AnnotationsLabel();
99   
100    }
101   
 
102  0 toggle public ViewPage getWrappedViewPage()
103    {
104  0 return this.viewPage;
105    }
106   
 
107  4 toggle public void addAnnotation(String annotatedText, String annotationText)
108    {
109  4 selectText(annotatedText);
110  4 simulateCTRL_M();
111  4 annotationsWindow.addAnnotation(annotationText);
112    // check is the saved successfully message is displayed
113  4 waitForNotificationSuccessMessage(XWIKI_ANNOTATION_ADD_SUCCESS);
114    }
115   
 
116  4 toggle public void deleteAnnotationByID(String id)
117    {
118  4 annotationsLabel.deleteAnnotationById(id);
119  4 waitForNotificationSuccessMessage(XWIKI_ANNOTATION_DELETE_SUCCESS);
120    }
121   
 
122  4 toggle public void deleteAnnotationByText(String annotatedText)
123    {
124  4 deleteAnnotationByID(this.annotationsLabel.getAnnotationIdByText(annotatedText));
125    }
126   
 
127  4 toggle public String getAnnotationContentByText(String searchText)
128    {
129  4 return annotationsLabel.getAnnotationContentByText(searchText);
130    }
131   
132    // Shows the annotations pane from the top of the page
 
133  2 toggle public void showAnnotationsPane()
134    {
135  2 annotationsPane.showAnnotationsPane();
136    }
137   
138    // Hides the annotations pane from the top of the page
 
139  0 toggle public void hideAnnotationsPane()
140    {
141  0 annotationsPane.hideAnnotationsPane();
142    }
143   
144    // Checks the "Show Annotations" check box.
 
145  0 toggle public void clickShowAnnotations()
146    {
147  0 annotationsPane.clickShowAnnotations();
148    }
149   
150    // Un-checks the "Show Annotations" check box.
 
151  0 toggle public void clickHideAnnotations()
152    {
153  0 annotationsPane.clickHideAnnotations();
154    }
155   
156    // Checks if the checkBox within AnnotationsPane is visible
 
157  0 toggle public boolean checkIfClickbuttonExists()
158    {
159  0 return annotationsPane.checkIfShowAnnotationsCheckboxExists();
160    }
161   
 
162  5 toggle public void simulateCTRL_M()
163    {
164  5 WebElement body = getDriver().findElement(By.id("body"));
165  5 body.sendKeys(Keys.chord(Keys.CONTROL, "m"));
166    }
167   
168    /**
169    * @param annotationWord string that will be selected on the screen
170    */
 
171  4 toggle public void selectText(String annotationWord)
172    {
173  4 ((JavascriptExecutor) getDriver()).executeScript(script + "findString('" + annotationWord + "');");
174    }
175   
 
176  1 toggle public boolean checkIfAnnotationsAreDisabled()
177    {
178  1 if (getDriver().findElementsWithoutWaiting(By.id("annotationsdisplay")).size() > 0)
179  0 return false;
180    else
181  1 return true;
182    }
183   
184    // Check if the bottom notifications warning appears that you are not allowed to annotate 1.0 syntax pages
 
185  1 toggle public void waitforAnnotationWarningNotification()
186    {
187  1 waitForNotificationWarningMessage(XWIKI_SYNTAX_1_WARNING);
188    }
189    }