首页 > 解决方案 > 在 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 文件中显示日语文本?

标签: javascriptjavaeclipseseleniumapplication.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"));
    }
}

推荐阅读