Path: blob/trunk/java/test/org/openqa/selenium/ContentEditableTest.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import static org.assertj.core.api.Assertions.assertThat;20import static org.junit.jupiter.api.Assumptions.assumeFalse;21import static org.openqa.selenium.testing.TestUtilities.getEffectivePlatform;22import static org.openqa.selenium.testing.TestUtilities.isFirefox;23import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;24import static org.openqa.selenium.testing.drivers.Browser.IE;25import static org.openqa.selenium.testing.drivers.Browser.SAFARI;2627import org.junit.jupiter.api.AfterEach;28import org.junit.jupiter.api.Test;29import org.openqa.selenium.testing.JupiterTestBase;30import org.openqa.selenium.testing.NotYetImplemented;3132class ContentEditableTest extends JupiterTestBase {3334@AfterEach35public void switchToDefaultContent() {36driver.switchTo().defaultContent();37}3839@Test40@NotYetImplemented(value = FIREFOX)41public void testTypingIntoAnIFrameWithContentEditableOrDesignModeSet() {42driver.get(pages.richTextPage);4344driver.switchTo().frame("editFrame");45WebElement element = driver.switchTo().activeElement();46element.sendKeys("Fishy");4748driver.switchTo().defaultContent();49WebElement trusted = driver.findElement(By.id("istrusted"));50WebElement id = driver.findElement(By.id("tagId"));5152assertThat(trusted.getText()).isIn("[true]", "[n/a]", "[]");53assertThat(id.getText()).isIn("[frameHtml]", "[theBody]");54}5556@Test57@NotYetImplemented(value = FIREFOX)58@NotYetImplemented(SAFARI)59public void testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() {60assumeFalse(61isFirefox(driver)62&& (getEffectivePlatform(driver).is(Platform.LINUX)63|| getEffectivePlatform(driver).is(Platform.MAC)),64"FIXME: Fails in Firefox on Linux with synthesized events");6566driver.get(pages.richTextPage);6768driver.switchTo().frame("editFrame");69WebElement element = driver.switchTo().activeElement();70element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT);71element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!");7273assertThat(element.getText()).isEqualTo("Fishee!");74}7576@Test77void testShouldBeAbleToTypeIntoEmptyContentEditableElement() {78driver.get(pages.readOnlyPage);79WebElement editable = driver.findElement(By.id("content-editable-blank"));8081editable.sendKeys("cheese");8283assertThat(editable.getText()).isEqualTo("cheese");84}8586@Test87@NotYetImplemented(SAFARI)88@NotYetImplemented(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/667")89public void testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue() {90driver.get(pages.readOnlyPage);91WebElement editable = driver.findElement(By.id("content-editable"));9293String initialText = editable.getText();94editable.sendKeys(", edited");9596assertThat(editable.getText()).isEqualTo(initialText + ", edited");97}9899@Test100void testShouldBeAbleToTypeIntoTinyMCE() {101driver.get(appServer.whereIs("tinymce.html"));102driver.switchTo().frame("mce_0_ifr");103104WebElement editable = driver.findElement(By.id("tinymce"));105106editable.clear();107editable.sendKeys("cheese"); // requires focus on OS X108109assertThat(editable.getText()).isEqualTo("cheese");110}111112@Test113@NotYetImplemented(value = IE, reason = "Prepends text")114@NotYetImplemented(value = SAFARI, reason = "Prepends text")115@NotYetImplemented(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/667")116public void testShouldAppendToTinyMCE() {117driver.get(appServer.whereIs("tinymce.html"));118driver.switchTo().frame("mce_0_ifr");119120WebElement editable = driver.findElement(By.id("tinymce"));121122editable.sendKeys(" and cheese"); // requires focus on OS X123124assertThat(editable.getText()).isEqualTo("Initial content and cheese");125}126127@Test128@NotYetImplemented(value = SAFARI, reason = "Prepends text")129public void appendsTextToEndOfContentEditableWithMultipleTextNodes() {130driver.get(appServer.whereIs("content-editable.html"));131WebElement input = driver.findElement(By.id("editable"));132input.sendKeys(", world!");133assertThat(input.getText()).isEqualTo("Why hello, world!");134}135}136137138