Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/test/org/openqa/selenium/I18nTest.java
4010 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.assumeTrue;
22
import static org.openqa.selenium.testing.drivers.Browser.CHROME;
23
import static org.openqa.selenium.testing.drivers.Browser.EDGE;
24
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;
25
import static org.openqa.selenium.testing.drivers.Browser.IE;
26
27
import org.junit.jupiter.api.Test;
28
import org.openqa.selenium.environment.GlobalTestEnvironment;
29
import org.openqa.selenium.testing.Ignore;
30
import org.openqa.selenium.testing.JupiterTestBase;
31
import org.openqa.selenium.testing.TestUtilities;
32
33
class I18nTest extends JupiterTestBase {
34
35
/** The Hebrew word shalom (peace) encoded in order Shin (sh) Lamed (L) Vav (O) final-Mem (M). */
36
private static final String shalom = "\u05E9\u05DC\u05D5\u05DD";
37
38
/**
39
* The Hebrew word tmunot (images) encoded in order Taf (t) Mem (m) Vav (u) Nun (n) Vav (o) Taf
40
* (t).
41
*/
42
private static final String tmunot = "\u05EA\u05DE\u05D5\u05E0\u05D5\u05EA";
43
44
/** Japanese for "Tokyo" */
45
private static final String tokyo = "\u6771\u4EAC";
46
47
/** Chinese for "The Voice of China" */
48
private static final String theVoiceOfChina = "\u4E2D\u56FD\u4E4B\u58F0";
49
50
@Test
51
void testCn() {
52
driver.get(pages.chinesePage);
53
driver.findElement(By.linkText(theVoiceOfChina)).click();
54
}
55
56
@Test
57
void testEnteringHebrewTextFromLeftToRight() {
58
driver.get(pages.chinesePage);
59
WebElement input = driver.findElement(By.name("i18n"));
60
61
input.sendKeys(shalom);
62
63
assertThat(input.getAttribute("value")).isEqualTo(shalom);
64
}
65
66
@Test
67
void testEnteringHebrewTextFromRightToLeft() {
68
driver.get(pages.chinesePage);
69
WebElement input = driver.findElement(By.name("i18n"));
70
71
input.sendKeys(tmunot);
72
73
assertThat(input.getAttribute("value")).isEqualTo(tmunot);
74
}
75
76
@Test
77
@Ignore(value = CHROME, reason = "ChromeDriver only supports characters in the BMP")
78
@Ignore(value = EDGE, reason = "EdgeDriver only supports characters in the BMP")
79
@Ignore(value = FIREFOX, reason = "https://github.com/mozilla/geckodriver/issues/2139")
80
public void testEnteringSupplementaryCharacters() {
81
driver.get(pages.chinesePage);
82
83
String input = "";
84
input += new String(Character.toChars(0x20000));
85
input += new String(Character.toChars(0x2070E));
86
input += new String(Character.toChars(0x2000B));
87
input += new String(Character.toChars(0x2A190));
88
input += new String(Character.toChars(0x2A6B2));
89
90
WebElement el = driver.findElement(By.name("i18n"));
91
el.sendKeys(input);
92
93
assertThat(el.getAttribute("value")).isEqualTo(input);
94
}
95
96
@Test
97
void testShouldBeAbleToReturnTheTextInAPage() {
98
String url = GlobalTestEnvironment.get().getAppServer().whereIs("encoding");
99
driver.get(url);
100
101
String text = driver.findElement(By.tagName("body")).getText();
102
103
assertThat(text).isEqualTo(shalom);
104
}
105
106
@Test
107
@Ignore(IE)
108
@Ignore(CHROME)
109
@Ignore(EDGE)
110
public void testShouldBeAbleToInputJapanese() {
111
assumeTrue(
112
TestUtilities.getEffectivePlatform(driver).is(Platform.LINUX),
113
"IME is supported on Linux only.");
114
115
driver.get(pages.formPage);
116
117
WebElement input = driver.findElement(By.id("working"));
118
119
// Activate IME. By default, this keycode activates IBus input for Japanese.
120
input.sendKeys(Keys.ZENKAKU_HANKAKU);
121
122
// Send the Romaji for "Tokyo". The space at the end instructs the IME to transform the word.
123
input.sendKeys("toukyou ");
124
125
String elementValue = input.getAttribute("value");
126
// Turn OFF IME input first.
127
input.sendKeys(Keys.ZENKAKU_HANKAKU);
128
129
// IME is not present. Don't fail because of that. But it should have the Romaji value
130
// instead.
131
assertThat(elementValue)
132
.describedAs("The element's value should either remain in Romaji or be converted properly.")
133
.isIn(tokyo, "\uE040" + "toukyou ", "toukyou ");
134
}
135
}
136
137