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

File MenuBarElement.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

4
19
8
1
136
55
10
0.53
2.38
8
1.25

Classes

Class Line # Actions
33 19 0% 10 13
0.5806451458.1%
 

Contributing tests

This file is covered by 1 test. .

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.WebElement;
24    import org.openqa.selenium.interactions.Actions;
25    import org.xwiki.test.ui.po.BaseElement;
26   
27    /**
28    * Models the menu bar of the WYSIWYG content editor.
29    *
30    * @version $Id: 3424911de04b7155da516e527bef11bc85381920 $
31    * @since 3.2M3
32    */
 
33    public class MenuBarElement extends BaseElement
34    {
35    /**
36    * The XPath used to locate a menu item by its label.
37    */
38    private static final String MENU_ITEM_XPATH = "//td[contains(@class, 'gwt-MenuItem') and . = '%s']";
39   
40    /**
41    * The element that wraps the menu bar.
42    */
43    private final WebElement container;
44   
45    /**
46    * Creates a new instance that can be used to control the menu bar inside the given container.
47    *
48    * @param container the element that wraps the menu bar
49    */
 
50  1 toggle public MenuBarElement(WebElement container)
51    {
52  1 this.container = container;
53    }
54   
55    /**
56    * Clicks on the image menu.
57    */
 
58  0 toggle public void clickImageMenu()
59    {
60  0 openMenuWithLabel("Image");
61    }
62   
63    /**
64    * Click on the table menu.
65    */
 
66  1 toggle public void clickTableMenu()
67    {
68  1 openMenuWithLabel("Table");
69    }
70   
71    /**
72    * Clicks on the "Attached Image..." menu.
73    *
74    * @return the pane used to select an attached image to insert
75    */
 
76  0 toggle public AttachedImageSelectPane clickInsertAttachedImageMenu()
77    {
78  0 String xpath = String.format(MENU_ITEM_XPATH, "Attached Image...");
79  0 WebElement insertAttachedImageMenu = container.findElement(By.xpath(xpath));
80  0 if (!isMenuEnabled(insertAttachedImageMenu)) {
81  0 return null;
82    }
83  0 insertAttachedImageMenu.click();
84  0 return new AttachedImageSelectPane().waitToLoad();
85    }
86   
87    /**
88    * Clicks on the "Insert Table..." menu.
89    *
90    * @return the pane used to configure the table to be inserted
91    */
 
92  1 toggle public TableConfigPane clickInsertTableMenu()
93    {
94  1 String xpath = String.format(MENU_ITEM_XPATH, "Insert Table...");
95  1 WebElement insertTableMenu = container.findElement(By.xpath(xpath));
96  1 if (!isMenuEnabled(insertTableMenu)) {
97  0 return null;
98    }
99  1 insertTableMenu.click();
100  1 return new TableConfigPane().waitToLoad();
101    }
102   
103    /**
104    * @param menu a menu item
105    * @return {@code true} of the given menu item is enabled, {@code false} otherwise
106    */
 
107  1 toggle private boolean isMenuEnabled(WebElement menu)
108    {
109  1 return !menu.getAttribute("class").contains("gwt-MenuItem-disabled");
110    }
111   
112    /**
113    * Opens a menu from the menu bar.
114    *
115    * @param label the label of the menu to open
116    */
 
117  1 toggle private void openMenuWithLabel(String label)
118    {
119    // Hover the menu bar to hide any page menus that may be displayed over the WYSIWYG editor menu bar. For
120    // instance, when you return from preview after clicking the "Back to edit" button, if the mouse is not moved it
121    // can end up over the edit menu after the page is loaded. This opens the edit menu which hides part of the
122    // WYSIWYG editor menu bar.
123  1 new Actions(getDriver()).moveToElement(container).perform();
124  1 clickMenuWithLabel(label);
125    }
126   
127    /**
128    * Clicks on the menu item with the given label.
129    *
130    * @param label the label of the menu item to click
131    */
 
132  1 toggle private void clickMenuWithLabel(String label)
133    {
134  1 container.findElement(By.xpath(String.format(MENU_ITEM_XPATH, label))).click();
135    }
136    }