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 /testbench-api/src | |
parent | 1121d795b6356baad0f7eba2a78fc4918ed93a01 (diff) | |
download | vaadin-framework-a2bd03aaf44ae0b335aa9ddcb592c81a9647cc70.tar.gz vaadin-framework-a2bd03aaf44ae0b335aa9ddcb592c81a9647cc70.zip |
Added support for getValue and setValue into TestBench RichTextAreaElement (#10659)
Diffstat (limited to 'testbench-api/src')
-rw-r--r-- | testbench-api/src/main/java/com/vaadin/testbench/elements/RichTextAreaElement.java | 41 |
1 files changed, 41 insertions, 0 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()); + } } |