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

File EditorElement.java

 

Coverage histogram

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

Code metrics

10
20
11
1
157
72
16
0.8
1.82
11
1.45

Classes

Class Line # Actions
EditorElement 33 20 0% 16 9
0.780487878%
 

Contributing tests

This file is covered by 9 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.wysiwyg.test.po;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.WebDriver;
24    import org.openqa.selenium.WebElement;
25    import org.openqa.selenium.support.ui.ExpectedCondition;
26   
27    /**
28    * Models a WYSIWYG editor instance.
29    *
30    * @version $Id: 6a9a88e431818936e47bc3a56dd85746d17c1554 $
31    * @since 5.1RC1
32    */
 
33    public class EditorElement extends org.xwiki.test.ui.po.editor.wysiwyg.EditorElement
34    {
35    /**
36    * The XPath used to select a editor tab (Source/WYSIWYG) by its label.
37    */
38    private static final String TAB_ITEM_XPATH = "//div[@role = 'tab' and . = '%s']";
39   
40    /**
41    * The menu bar.
42    */
43    private MenuBarElement menuBar;
44   
45    /**
46    * The tool bar.
47    */
48    private ToolBarElement toolBar;
49   
50    /**
51    * Creates a new instance that can be used to control the WYSIWYG editor that replaced the specified form field.
52    *
53    * @param fieldId the id of the text area field that was replaced by the WYSIWYG editor.
54    */
 
55  19 toggle public EditorElement(String fieldId)
56    {
57  19 super(fieldId);
58    }
59   
60    /**
61    * @return the menu bar
62    */
 
63  2 toggle public MenuBarElement getMenuBar()
64    {
65  2 if (menuBar == null) {
66  1 menuBar = new MenuBarElement(getContainer().findElement(By.className("gwt-MenuBar-horizontal")));
67    }
68  2 return menuBar;
69    }
70   
71    /**
72    * @return the tool bar
73    */
 
74  0 toggle public ToolBarElement getToolBar()
75    {
76  0 if (toolBar == null) {
77  0 toolBar = new ToolBarElement(getContainer().findElement(By.className("xToolbar")));
78    }
79  0 return toolBar;
80    }
81   
82    /**
83    * @return the source text area
84    */
 
85  8 toggle public WebElement getSourceTextArea()
86    {
87  8 return getContainer().findElement(By.className("xPlainTextEditor"));
88    }
89   
90    /**
91    * Switches to the Source editor by clicking on the "Source" tab item and waits for the source text area to be
92    * initialized.
93    */
 
94  4 toggle public void switchToSource()
95    {
96  4 switchToSource(true);
97    }
98   
99    /**
100    * Switches to the Source editor by clicking on the "Source" tab item.
101    *
102    * @param wait {@code true} to wait for the source text area to be initialized, {@code false} otherwise
103    */
 
104  4 toggle public void switchToSource(boolean wait)
105    {
106  4 getContainer().findElement(By.xpath(String.format(TAB_ITEM_XPATH, "Source"))).click();
107  4 if (wait) {
108  4 waitForSourceTextArea(true);
109    }
110    }
111   
112    /**
113    * Switches to the WYSIWYG editor by clicking on the "WYSIWYG" tab item and waits for the rich text area to be
114    * initialized.
115    */
 
116  2 toggle public void switchToWysiwyg()
117    {
118  2 switchToWysiwyg(true);
119    }
120   
121    /**
122    * Switches the WYSIWYG editor by clicking on the "WYSIWYG" tab item.
123    *
124    * @param wait {@code true} to wait for the rich text area to be initialized, {@code false} otherwise
125    */
 
126  2 toggle public void switchToWysiwyg(boolean wait)
127    {
128  2 getContainer().findElement(By.xpath(String.format(TAB_ITEM_XPATH, "WYSIWYG"))).click();
129  2 if (wait) {
130  2 waitForSourceTextArea(false);
131    }
132    }
133   
134    /**
135    * Waits for the source text area to have the specified state.
136    *
137    * @param enabled whether the source text area should be enabled or disabled
138    */
 
139  6 toggle private void waitForSourceTextArea(final boolean enabled)
140    {
141  6 getDriver().waitUntilCondition(new ExpectedCondition<WebElement>()
142    {
 
143  6 toggle @Override
144    public WebElement apply(WebDriver driver)
145    {
146  6 WebElement sourceTextArea = getContainer().findElement(By.className("xPlainTextEditor"));
147  6 return sourceTextArea.isEnabled() == enabled ? sourceTextArea : null;
148    }
149    });
150    }
151   
 
152  8 toggle @Override
153    public EditorElement waitToLoad()
154    {
155  8 return (EditorElement) super.waitToLoad();
156    }
157    }