javascript - 在 testdata.properties 文件中显示非英语语言
问题描述
我正在使用 testdata.properties 文件将值传递到我的 selenium 测试脚本中。当我进入
Chinese Charachter : 成長促進
japanese Charachter :`へのコミットメント
在 testdata.properties 文件中,它显示为
chinese charachter :: \u6210\u9577\u4FC3\u9032
japanese charachter :: \u3078\u306E\u30B3\u30DF\u30C3\u30C8\u30E1\u30F3\u30C8
请让我知道如何在 testdata.properties 文件中显示日语文本?
解决方案
默认情况下,eclipse 提供的编码是“ISO 8859-1 编码”,因此当您粘贴任何本地语言代码时,例如粘贴中文和日文,它会默认将其转换为nativeToAscii编码。
需要在 Eclipse 中将“ISO 8859-1 编码”更改为“UTF-8”。
转到 Eclipse - Windows - 首选项 - 搜索内容类型
现在将该编码更改为“UTF-8”,它将以本地语言显示您的属性文件。首先更新您的编码,然后应用并关闭。
当您将数据设置为“ISO 8859-1 编码”并使用 sendkeys 时,它将自动通过本地语言发送数据。
请参阅下面的代码片段。
package com.software.testing;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Testingclass extends DriverFactory {
private static WebDriver driver = null;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File file = new File("C:\\Users\\eclipse-workspace\\SoftwareTesting\\testdata.properties");
FileInputStream fileInput = null;
try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Properties prop = new Properties();
// load properties file
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
}
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Desktop\\ChromeDriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("http://www.google.com");
driver.findElement(By.xpath("//input[@title='Search']")).sendKeys(prop.getProperty("japanese"));
//driver.findElement(By.id("q")).sendKeys(prop.getProperty("chinese"));
}
}
推荐阅读
- r - 从 R 认证到 Linkedin API
- c++ - 在资源管理器替换程序的文件夹 (SHOpenFolderAndSelectItems) 中显示
- python - Python 装饰器早期解析破坏了前向声明
- powershell - 如何调用在 for 循环中创建的变量?
- sql-server - SQL Server 中具有空值多列的平均值
- firebase - 在 Flutter 中返回 Null 的可调用云函数
- amazon-web-services - 如何确定使用 AWS Terraform 资源所需的 AWS IAM 策略权限?
- java - 即使使用@JsonInclude(JsonInclude.Include.NON_EMPTY),当所有属性都为空或为空时,如何防止空复杂对象?
- flask - Flask-SQLAlchemy 通过一个查询获取带有子代的父代
- c# - 类型化 HttpClient 与 IHttpClientFactory