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

File EditorElement.java

 
testUploadImageAfterPreview: Timed out after 10 seconds waiting for org.xwiki.test.ui....
 

Coverage histogram

../../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
17
6
1
114
56
10
0.59
2.83
6
1.67

Classes

Class Line # Actions
EditorElement 35 17 0% 10 1
0.9696%
 

Contributing tests

This file is covered by 25 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.editor.wysiwyg;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.NotFoundException;
24    import org.openqa.selenium.WebDriver;
25    import org.openqa.selenium.WebElement;
26    import org.openqa.selenium.support.ui.ExpectedCondition;
27    import org.xwiki.test.ui.po.BaseElement;
28   
29    /**
30    * Models a WYSIWYG editor instance.
31    *
32    * @version $Id: 900991da55d78b49d7fe3905f12166dc8e881118 $
33    * @since 3.2M3
34    */
 
35    public class EditorElement extends BaseElement
36    {
37    /**
38    * The id of the form field field replaced the WYSIWYG editor.
39    */
40    private final String fieldId;
41   
42    /**
43    * Creates a new instance that can be used to control the WYSIWYG editor that replaced the specified form field.
44    *
45    * @param fieldId the id of the text area field that was replaced by the WYSIWYG editor.
46    */
 
47  69 toggle public EditorElement(String fieldId)
48    {
49  69 this.fieldId = fieldId;
50    }
51   
52    /**
53    * @return the rich text area
54    */
 
55  22 toggle public RichTextAreaElement getRichTextArea()
56    {
57    // The in-line frame element is renewed while editing so we can't cache it.
58  22 return new RichTextAreaElement(getContainer().findElement(By.className("gwt-RichTextArea")));
59    }
60   
61    /**
62    * Waits for the WYSIWYG content editor to load.
63    */
 
64  54 toggle public EditorElement waitToLoad()
65    {
66  54 Test failure here getDriver().waitUntilCondition(new ExpectedCondition<WebElement>()
67    {
 
68  91 toggle @Override
69    public WebElement apply(WebDriver driver)
70    {
71  91 try {
72    // Source tab in WYSIWYG editor 2.x syntax
73  91 getContainer(driver).findElement(
74    By.xpath("//div[@class = 'gwt-TabBarItem gwt-TabBarItem-selected']/div[. = 'Source']"));
75  1 WebElement sourceTextArea = getContainer(driver).findElement(By.className("xPlainTextEditor"));
76  1 return sourceTextArea.isEnabled() ? sourceTextArea : null;
77    } catch (NotFoundException sourceNotFound) {
78  90 try {
79    // WYSIWYG editor 2.x syntax
80  90 WebElement richTextEditor = getContainer(driver).findElement(By.className("xRichTextEditor"));
81  55 try {
82  55 richTextEditor.findElement(By.className("loading"));
83  3 return null;
84    } catch (NotFoundException loadingNotFound) {
85  52 return richTextEditor;
86    }
87    } catch (NotFoundException xRichTextEditorNotFound) {
88  35 return null;
89    }
90    }
91    }
92    });
93  53 return this;
94    }
95   
96    /**
97    * Note: Uses the passed driver, this is important since this is called by code within a Wait class, using the
98    * wrapped driver.
99    *
100    * @return the element that wraps the editor
101    */
 
102  226 toggle private WebElement getContainer(WebDriver driver)
103    {
104  226 return driver.findElement(By.xpath("//div[starts-with(@id, '" + fieldId + "_container')]"));
105    }
106   
107    /**
108    * @return the element that wraps the editor
109    */
 
110  44 toggle protected WebElement getContainer()
111    {
112  44 return getContainer(getDriver());
113    }
114    }