diff options
author | Anastasia Smirnova <anasmi@utu.fi> | 2018-04-10 13:51:51 +0300 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2018-04-10 13:51:51 +0300 |
commit | a2bd03aaf44ae0b335aa9ddcb592c81a9647cc70 (patch) | |
tree | 71984e007a7ef06e494c8e827cb7617012c1abba | |
parent | 1121d795b6356baad0f7eba2a78fc4918ed93a01 (diff) | |
download | vaadin-framework-a2bd03aaf44ae0b335aa9ddcb592c81a9647cc70.tar.gz vaadin-framework-a2bd03aaf44ae0b335aa9ddcb592c81a9647cc70.zip |
Added support for getValue and setValue into TestBench RichTextAreaElement (#10659)
5 files changed, 84 insertions, 10 deletions
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java index 2728468a3e..d6ce571f01 100644 --- a/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java +++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java @@ -15,6 +15,7 @@ */ package com.vaadin.testbench.elements; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebElement; import com.vaadin.testbench.By; @@ -33,4 +34,44 @@ public class RichTextAreaElement extends AbstractFieldElement { public WebElement getEditorIframe() { return findElement(By.tagName("iframe")); } + + /** + * Return value of the field element. + * + * @return value of the field element + * @since + */ + public String getValue() { + JavascriptExecutor executor = (JavascriptExecutor) getDriver(); + return executor.executeScript( + "return arguments[0].contentDocument.body.innerHTML", + getEditorIframe()).toString(); + } + + /** + * Set value of the field element. + * + * @param chars + * new value of the field + * @since + */ + public void setValue(CharSequence chars) throws ReadOnlyException { + if (isReadOnly()) { + throw new ReadOnlyException(); + } + JavascriptExecutor executor = (JavascriptExecutor) getDriver(); + executor.executeScript("var bodyE=arguments[0].contentDocument.body;\n" + + "bodyE.innerHTML=arguments[1]; \n" + + "var ev = document.createEvent('HTMLEvents');\n" + + "ev.initEvent('change', true, false); \n" + + "bodyE.dispatchEvent(ev);", getEditorIframe(), chars); + } + + @Override + public void focus() { + waitForVaadin(); + JavascriptExecutor executor = (JavascriptExecutor) getDriver(); + executor.executeScript("arguments[0].contentDocument.body.focus();", + getEditorIframe()); + } } diff --git a/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java index 3c06ae4c11..2b00ca7d1d 100644 --- a/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java +++ b/uitest/src/main/java/com/vaadin/tests/elements/ComponentElementGetValue.java @@ -22,11 +22,13 @@ import com.vaadin.ui.Slider; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; import com.vaadin.ui.TwinColSelect; +import com.vaadin.ui.RichTextArea; + /** * UI test for getValue() method of components: TextField, TextArea, * PasswordField, ComboBox, ListSelect, NativeSelect, OptionGroup, CheckBox, - * DateField, TwinColSelect + * DateField, TwinColSelect, RichTextArea * * @author Vaadin Ltd */ @@ -34,9 +36,8 @@ public class ComponentElementGetValue extends AbstractTestUI { public static final String TEST_STRING_VALUE = "item 2"; public static final int TEST_SLIDER_VALUE = 42; - public static final float TEST_FLOAT_VALUE = 0.42f; public static final LocalDate TEST_DATE_VALUE = LocalDate.now(); - DateField df; + public static final String TESTGET_STRING_VALUE_RICHTEXTAREA = "value 4"; final Label valueChangeLabel = new Label("Initial value"); // These constants are used to check that change value event was @@ -105,7 +106,7 @@ public class ComponentElementGetValue extends AbstractTestUI { event -> valueChangeLabel.setValue(value)); addComponent(field); } - + addComponent(createRichTextArea()); addComponent(createCheckBox()); addComponent(createSlider()); addComponent(createDateField()); @@ -137,6 +138,12 @@ public class ComponentElementGetValue extends AbstractTestUI { return cb; } + private RichTextArea createRichTextArea() { + RichTextArea rta = new RichTextArea(); + rta.setValue(TESTGET_STRING_VALUE_RICHTEXTAREA); + return rta; + } + @Override protected String getTestDescription() { return "Field elements getValue() should return test value"; diff --git a/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java index 97abfd1be6..8d724f4bfb 100644 --- a/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java +++ b/uitest/src/main/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValue.java @@ -11,6 +11,7 @@ import com.vaadin.ui.Label; import com.vaadin.ui.PasswordField; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; +import com.vaadin.ui.RichTextArea; public class AbstractTextElementSetValue extends AbstractTestUI { @@ -33,6 +34,7 @@ public class AbstractTextElementSetValue extends AbstractTestUI { addValueChangeListener(comps[i], i); addComponent(comps[i]); addComponent(eventCountLabels[i]); + addComponent(createRichTextArea()); } @@ -61,6 +63,12 @@ public class AbstractTextElementSetValue extends AbstractTestUI { return df; } + private RichTextArea createRichTextArea() { + RichTextArea rta = new RichTextArea(); + rta.setValue(INITIAL_VALUE); + return rta; + } + @Override protected String getTestDescription() { return "Test type method of AbstractTextField components"; diff --git a/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java index 50c24e289e..f6f7e7f3c9 100644 --- a/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java +++ b/uitest/src/test/java/com/vaadin/tests/elements/ComponentElementGetValueTest.java @@ -6,9 +6,6 @@ import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; - import com.vaadin.testbench.elements.AbstractTextFieldElement; import com.vaadin.testbench.elements.CheckBoxElement; import com.vaadin.testbench.elements.CheckBoxGroupElement; @@ -21,6 +18,10 @@ import com.vaadin.testbench.elements.RadioButtonGroupElement; import com.vaadin.testbench.elements.TextAreaElement; import com.vaadin.testbench.elements.TextFieldElement; import com.vaadin.testbench.elements.TwinColSelectElement; +import com.vaadin.testbench.elements.RichTextAreaElement; +import org.junit.Before; +import org.junit.Test; + import com.vaadin.tests.tb3.MultiBrowserTest; public class ComponentElementGetValueTest extends MultiBrowserTest { @@ -115,6 +116,14 @@ public class ComponentElementGetValueTest extends MultiBrowserTest { assertEquals(expected, actual); } + @Test + public void checkRichTextArea() { + RichTextAreaElement elem = $(RichTextAreaElement.class).first(); + String expected = ComponentElementGetValue.TESTGET_STRING_VALUE_RICHTEXTAREA; + String actual = elem.getValue(); + assertEquals(expected, actual); + } + private void checkValue(AbstractTextFieldElement elem) { String expected = ComponentElementGetValue.TEST_STRING_VALUE; String actual = elem.getValue(); diff --git a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java index c65e3e3b65..d89437da60 100644 --- a/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java +++ b/uitest/src/test/java/com/vaadin/tests/elements/abstracttextfield/AbstractTextElementSetValueTest.java @@ -2,15 +2,16 @@ package com.vaadin.tests.elements.abstracttextfield; import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; - import com.vaadin.testbench.elements.AbstractTextFieldElement; import com.vaadin.testbench.elements.DateFieldElement; import com.vaadin.testbench.elements.LabelElement; import com.vaadin.testbench.elements.PasswordFieldElement; import com.vaadin.testbench.elements.TextAreaElement; import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.testbench.elements.RichTextAreaElement; +import org.junit.Before; +import org.junit.Test; + import com.vaadin.tests.tb3.MultiBrowserTest; public class AbstractTextElementSetValueTest extends MultiBrowserTest { @@ -49,6 +50,14 @@ public class AbstractTextElementSetValueTest extends MultiBrowserTest { assertEquals(TYPED_STRING, elem.getValue()); } + @Test + public void richTextAreaSetValue() { + RichTextAreaElement elem = $(RichTextAreaElement.class).get(0); + elem.setValue(TYPED_STRING); + String actual = elem.getValue(); + assertEquals(TYPED_STRING, actual); + } + // helper methods // checks that setValue method works private void checkType(AbstractTextFieldElement elem, |