Path: blob/trunk/java/test/org/openqa/selenium/I18nTest.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.assumeTrue;21import static org.openqa.selenium.testing.drivers.Browser.*;2223import org.junit.jupiter.api.Test;24import org.openqa.selenium.environment.GlobalTestEnvironment;25import org.openqa.selenium.testing.Ignore;26import org.openqa.selenium.testing.JupiterTestBase;27import org.openqa.selenium.testing.TestUtilities;2829class I18nTest extends JupiterTestBase {3031/** The Hebrew word shalom (peace) encoded in order Shin (sh) Lamed (L) Vav (O) final-Mem (M). */32private static final String shalom = "\u05E9\u05DC\u05D5\u05DD";3334/**35* The Hebrew word tmunot (images) encoded in order Taf (t) Mem (m) Vav (u) Nun (n) Vav (o) Taf36* (t).37*/38private static final String tmunot = "\u05EA\u05DE\u05D5\u05E0\u05D5\u05EA";3940/** Japanese for "Tokyo" */41private static final String tokyo = "\u6771\u4EAC";4243/** Chinese for "The Voice of China" */44private static final String theVoiceOfChina = "\u4E2D\u56FD\u4E4B\u58F0";4546@Test47void testCn() {48driver.get(pages.chinesePage);49driver.findElement(By.linkText(theVoiceOfChina)).click();50}5152@Test53void testEnteringHebrewTextFromLeftToRight() {54driver.get(pages.chinesePage);55WebElement input = driver.findElement(By.name("i18n"));5657input.sendKeys(shalom);5859assertThat(input.getAttribute("value")).isEqualTo(shalom);60}6162@Test63void testEnteringHebrewTextFromRightToLeft() {64driver.get(pages.chinesePage);65WebElement input = driver.findElement(By.name("i18n"));6667input.sendKeys(tmunot);6869assertThat(input.getAttribute("value")).isEqualTo(tmunot);70}7172@Test73@Ignore(value = CHROME, reason = "ChromeDriver only supports characters in the BMP")74@Ignore(value = EDGE, reason = "EdgeDriver only supports characters in the BMP")75@Ignore(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/2139")76public void testEnteringSupplementaryCharacters() {77driver.get(pages.chinesePage);7879String input = "";80input += new String(Character.toChars(0x20000));81input += new String(Character.toChars(0x2070E));82input += new String(Character.toChars(0x2000B));83input += new String(Character.toChars(0x2A190));84input += new String(Character.toChars(0x2A6B2));8586WebElement el = driver.findElement(By.name("i18n"));87el.sendKeys(input);8889assertThat(el.getAttribute("value")).isEqualTo(input);90}9192@Test93void testShouldBeAbleToReturnTheTextInAPage() {94String url = GlobalTestEnvironment.get().getAppServer().whereIs("encoding");95driver.get(url);9697String text = driver.findElement(By.tagName("body")).getText();9899assertThat(text).isEqualTo(shalom);100}101102@Test103@Ignore(IE)104@Ignore(CHROME)105@Ignore(EDGE)106public void testShouldBeAbleToInputJapanese() {107assumeTrue(108TestUtilities.getEffectivePlatform(driver).is(Platform.LINUX),109"IME is supported on Linux only.");110111driver.get(pages.formPage);112113WebElement input = driver.findElement(By.id("working"));114115// Activate IME. By default, this keycode activates IBus input for Japanese.116input.sendKeys(Keys.ZENKAKU_HANKAKU);117118// Send the Romaji for "Tokyo". The space at the end instructs the IME to transform the word.119input.sendKeys("toukyou ");120121String elementValue = input.getAttribute("value");122// Turn OFF IME input first.123input.sendKeys(Keys.ZENKAKU_HANKAKU);124125// IME is not present. Don't fail because of that. But it should have the Romaji value126// instead.127assertThat(elementValue)128.describedAs("The element's value should either remain in Romaji or be converted properly.")129.isIn(tokyo, "\uE040" + "toukyou ", "toukyou ");130}131}132133134