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

File RichTextAreaElement.java

 

Coverage histogram

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

Code metrics

0
26
9
1
152
72
9
0.35
2.89
9
1

Classes

Class Line # Actions
RichTextAreaElement 34 26 0% 9 5
0.8571428785.7%
 

Contributing tests

This file is covered by 213 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.wysiwyg.framework;
21   
22    import org.openqa.selenium.JavascriptExecutor;
23    import org.openqa.selenium.WebDriver;
24    import org.openqa.selenium.WebElement;
25   
26    /**
27    * Models the rich text area of the WYSIWYG content editor.
28    * <p>
29    * NOTE: This class is temporary until we move the tests to Selenium 2.
30    *
31    * @version $Id: aac2671a81b8254dc3eb6aeb15570c5174f82746 $
32    * @since 3.2M3
33    */
 
34    public class RichTextAreaElement
35    {
36    private final WebDriver driver;
37   
38    /**
39    * The in-line frame element.
40    */
41    private final WebElement iframe;
42   
43    /**
44    * Creates a new rich text area element.
45    *
46    * @param iframe the in-line frame used by the rich text area
47    */
 
48  968 toggle public RichTextAreaElement(WebDriver driver, WebElement iframe)
49    {
50  968 this.driver = driver;
51  968 this.iframe = iframe;
52    }
53   
54    /**
55    * @return the {@link WebDriver} instance
56    */
 
57  3231 toggle protected WebDriver getDriver()
58    {
59  3231 return driver;
60    }
61   
62    /**
63    * @return the inner text of the rich text area
64    */
 
65  12 toggle public String getText()
66    {
67  12 String windowHandle = getDriver().getWindowHandle();
68  12 try {
69  12 return getDriver().switchTo().frame(iframe).switchTo().activeElement().getText();
70    } finally {
71  12 getDriver().switchTo().window(windowHandle);
72    }
73    }
74   
75    /**
76    * Clears the content of the rich text area.
77    */
 
78  0 toggle public void clear()
79    {
80  0 String windowHandle = getDriver().getWindowHandle();
81  0 try {
82  0 getDriver().switchTo().frame(iframe).switchTo().activeElement().clear();
83    } finally {
84  0 getDriver().switchTo().window(windowHandle);
85    }
86    }
87   
88    /**
89    * Clicks on the rich text area.
90    */
 
91  3 toggle public void click()
92    {
93  3 String windowHandle = getDriver().getWindowHandle();
94  3 try {
95  3 getDriver().switchTo().frame(iframe).switchTo().activeElement().click();
96    } finally {
97  3 getDriver().switchTo().window(windowHandle);
98    }
99    }
100   
101    /**
102    * Simulate typing in the rich text area.
103    *
104    * @param keysToSend the sequence of keys to by typed
105    */
 
106  626 toggle public void sendKeys(CharSequence... keysToSend)
107    {
108  626 String windowHandle = getDriver().getWindowHandle();
109  626 try {
110  626 getDriver().switchTo().frame(iframe).switchTo().activeElement().sendKeys(keysToSend);
111    } finally {
112  626 getDriver().switchTo().window(windowHandle);
113    }
114    }
115   
116    /**
117    * Executes the given script in the context of the rich text area.
118    *
119    * @param script the script to be executed
120    * @param arguments the script arguments
121    * @return the result of the script execution
122    * @see JavascriptExecutor#executeScript(String, Object...)
123    */
 
124  327 toggle public Object executeScript(String script, Object... arguments)
125    {
126  327 String windowHandle = getDriver().getWindowHandle();
127  327 try {
128  327 getDriver().switchTo().frame(iframe).switchTo().activeElement();
129  327 return ((JavascriptExecutor) getDriver()).executeScript(script.toString(), arguments);
130    } finally {
131  327 getDriver().switchTo().window(windowHandle);
132    }
133    }
134   
135    /**
136    * @return the HTML content of the rich text area
137    */
 
138  78 toggle public String getContent()
139    {
140  78 return (String) executeScript("return document.body.innerHTML");
141    }
142   
143    /**
144    * Sets the HTML content of the rich text area
145    *
146    * @param content the new HTML content
147    */
 
148  20 toggle public void setContent(String content)
149    {
150  20 executeScript("document.body.innerHTML = arguments[0];", content);
151    }
152    }