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