Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/ContentEditableTest.java
1865 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
package org.openqa.selenium;
19
20
import static org.assertj.core.api.Assertions.assertThat;
21
import static org.junit.jupiter.api.Assumptions.assumeFalse;
22
import static org.openqa.selenium.testing.TestUtilities.getEffectivePlatform;
23
import static org.openqa.selenium.testing.TestUtilities.isFirefox;
24
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
25
import static org.openqa.selenium.testing.drivers.Browser.IE;
26
import static org.openqa.selenium.testing.drivers.Browser.SAFARI;
27
28
import org.junit.jupiter.api.AfterEach;
29
import org.junit.jupiter.api.Test;
30
import org.openqa.selenium.testing.JupiterTestBase;
31
import org.openqa.selenium.testing.NotYetImplemented;
32
33
class ContentEditableTest extends JupiterTestBase {
34
35
@AfterEach
36
public void switchToDefaultContent() {
37
driver.switchTo().defaultContent();
38
}
39
40
@Test
41
@NotYetImplemented(value = FIREFOX)
42
public void testTypingIntoAnIFrameWithContentEditableOrDesignModeSet() {
43
driver.get(pages.richTextPage);
44
45
driver.switchTo().frame("editFrame");
46
WebElement element = driver.switchTo().activeElement();
47
element.sendKeys("Fishy");
48
49
driver.switchTo().defaultContent();
50
WebElement trusted = driver.findElement(By.id("istrusted"));
51
WebElement id = driver.findElement(By.id("tagId"));
52
53
assertThat(trusted.getText()).isIn("[true]", "[n/a]", "[]");
54
assertThat(id.getText()).isIn("[frameHtml]", "[theBody]");
55
}
56
57
@Test
58
@NotYetImplemented(value = FIREFOX)
59
@NotYetImplemented(SAFARI)
60
public void testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() {
61
assumeFalse(
62
isFirefox(driver)
63
&& (getEffectivePlatform(driver).is(Platform.LINUX)
64
|| getEffectivePlatform(driver).is(Platform.MAC)),
65
"FIXME: Fails in Firefox on Linux with synthesized events");
66
67
driver.get(pages.richTextPage);
68
69
driver.switchTo().frame("editFrame");
70
WebElement element = driver.switchTo().activeElement();
71
element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT);
72
element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!");
73
74
assertThat(element.getText()).isEqualTo("Fishee!");
75
}
76
77
@Test
78
void testShouldBeAbleToTypeIntoEmptyContentEditableElement() {
79
driver.get(pages.readOnlyPage);
80
WebElement editable = driver.findElement(By.id("content-editable-blank"));
81
82
editable.sendKeys("cheese");
83
84
assertThat(editable.getText()).isEqualTo("cheese");
85
}
86
87
@Test
88
@NotYetImplemented(SAFARI)
89
@NotYetImplemented(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/667")
90
public void testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue() {
91
driver.get(pages.readOnlyPage);
92
WebElement editable = driver.findElement(By.id("content-editable"));
93
94
String initialText = editable.getText();
95
editable.sendKeys(", edited");
96
97
assertThat(editable.getText()).isEqualTo(initialText + ", edited");
98
}
99
100
@Test
101
void testShouldBeAbleToTypeIntoTinyMCE() {
102
driver.get(appServer.whereIs("tinymce.html"));
103
driver.switchTo().frame("mce_0_ifr");
104
105
WebElement editable = driver.findElement(By.id("tinymce"));
106
107
editable.clear();
108
editable.sendKeys("cheese"); // requires focus on OS X
109
110
assertThat(editable.getText()).isEqualTo("cheese");
111
}
112
113
@Test
114
@NotYetImplemented(value = IE, reason = "Prepends text")
115
@NotYetImplemented(value = SAFARI, reason = "Prepends text")
116
@NotYetImplemented(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/667")
117
public void testShouldAppendToTinyMCE() {
118
driver.get(appServer.whereIs("tinymce.html"));
119
driver.switchTo().frame("mce_0_ifr");
120
121
WebElement editable = driver.findElement(By.id("tinymce"));
122
123
editable.sendKeys(" and cheese"); // requires focus on OS X
124
125
assertThat(editable.getText()).isEqualTo("Initial content and cheese");
126
}
127
128
@Test
129
@NotYetImplemented(value = SAFARI, reason = "Prepends text")
130
public void appendsTextToEndOfContentEditableWithMultipleTextNodes() {
131
driver.get(appServer.whereIs("content-editable.html"));
132
WebElement input = driver.findElement(By.id("editable"));
133
input.sendKeys(", world!");
134
assertThat(input.getText()).isEqualTo("Why hello, world!");
135
}
136
}
137
138