Path: blob/trunk/java/test/org/openqa/selenium/I18nTest.java
4010 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.assumeTrue;21import static org.openqa.selenium.testing.drivers.Browser.CHROME;22import static org.openqa.selenium.testing.drivers.Browser.EDGE;23import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;24import static org.openqa.selenium.testing.drivers.Browser.IE;2526import org.junit.jupiter.api.Test;27import org.openqa.selenium.environment.GlobalTestEnvironment;28import org.openqa.selenium.testing.Ignore;29import org.openqa.selenium.testing.JupiterTestBase;30import org.openqa.selenium.testing.TestUtilities;3132class I18nTest extends JupiterTestBase {3334/** The Hebrew word shalom (peace) encoded in order Shin (sh) Lamed (L) Vav (O) final-Mem (M). */35private static final String shalom = "\u05E9\u05DC\u05D5\u05DD";3637/**38* The Hebrew word tmunot (images) encoded in order Taf (t) Mem (m) Vav (u) Nun (n) Vav (o) Taf39* (t).40*/41private static final String tmunot = "\u05EA\u05DE\u05D5\u05E0\u05D5\u05EA";4243/** Japanese for "Tokyo" */44private static final String tokyo = "\u6771\u4EAC";4546/** Chinese for "The Voice of China" */47private static final String theVoiceOfChina = "\u4E2D\u56FD\u4E4B\u58F0";4849@Test50void testCn() {51driver.get(pages.chinesePage);52driver.findElement(By.linkText(theVoiceOfChina)).click();53}5455@Test56void testEnteringHebrewTextFromLeftToRight() {57driver.get(pages.chinesePage);58WebElement input = driver.findElement(By.name("i18n"));5960input.sendKeys(shalom);6162assertThat(input.getAttribute("value")).isEqualTo(shalom);63}6465@Test66void testEnteringHebrewTextFromRightToLeft() {67driver.get(pages.chinesePage);68WebElement input = driver.findElement(By.name("i18n"));6970input.sendKeys(tmunot);7172assertThat(input.getAttribute("value")).isEqualTo(tmunot);73}7475@Test76@Ignore(value = CHROME, reason = "ChromeDriver only supports characters in the BMP")77@Ignore(value = EDGE, reason = "EdgeDriver only supports characters in the BMP")78@Ignore(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/2139")79public void testEnteringSupplementaryCharacters() {80driver.get(pages.chinesePage);8182String input = "";83input += new String(Character.toChars(0x20000));84input += new String(Character.toChars(0x2070E));85input += new String(Character.toChars(0x2000B));86input += new String(Character.toChars(0x2A190));87input += new String(Character.toChars(0x2A6B2));8889WebElement el = driver.findElement(By.name("i18n"));90el.sendKeys(input);9192assertThat(el.getAttribute("value")).isEqualTo(input);93}9495@Test96void testShouldBeAbleToReturnTheTextInAPage() {97String url = GlobalTestEnvironment.get().getAppServer().whereIs("encoding");98driver.get(url);99100String text = driver.findElement(By.tagName("body")).getText();101102assertThat(text).isEqualTo(shalom);103}104105@Test106@Ignore(IE)107@Ignore(CHROME)108@Ignore(EDGE)109public void testShouldBeAbleToInputJapanese() {110assumeTrue(111TestUtilities.getEffectivePlatform(driver).is(Platform.LINUX),112"IME is supported on Linux only.");113114driver.get(pages.formPage);115116WebElement input = driver.findElement(By.id("working"));117118// Activate IME. By default, this keycode activates IBus input for Japanese.119input.sendKeys(Keys.ZENKAKU_HANKAKU);120121// Send the Romaji for "Tokyo". The space at the end instructs the IME to transform the word.122input.sendKeys("toukyou ");123124String elementValue = input.getAttribute("value");125// Turn OFF IME input first.126input.sendKeys(Keys.ZENKAKU_HANKAKU);127128// IME is not present. Don't fail because of that. But it should have the Romaji value129// instead.130assertThat(elementValue)131.describedAs("The element's value should either remain in Romaji or be converted properly.")132.isIn(tokyo, "\uE040" + "toukyou ", "toukyou ");133}134}135136137