Java TestNG/Maven编码问题

Java TestNG/Maven编码问题,java,maven,selenium,testng,Java,Maven,Selenium,Testng,我在Maven项目中使用TestNG,在测试用例中使用.xlsx文件中的数据。虽然该数据在控制台中正确打印,但TestNG无法正确读取某些字符(Î到Ã、Î到Ã、ç到ç) 我几乎尝试了我能找到的每一个“解决方案”,但都无济于事 类文件: @Test(groups = {"customer"}, dataProvider = "customerData", dataProviderClass = Testdata.class, priority = 0) public void cr

我在Maven项目中使用TestNG,在测试用例中使用.xlsx文件中的数据。虽然该数据在控制台中正确打印,但TestNG无法正确读取某些字符(Î到Ã、Î到Ã、ç到ç)

我几乎尝试了我能找到的每一个“解决方案”,但都无济于事

类文件:

   @Test(groups = {"customer"}, dataProvider = "customerData", dataProviderClass = Testdata.class, priority = 0)
   public void createCustomer(String cName) throws InterruptedException {
       System.out.println(cName);
       ...
}
testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="NAV_Integration_TestSuite">
 <test name="Customer creation">
   <classes>
     <class name="test.customer.CRn"/>
   </classes>
 </test>
</suite>

readExcel:

    public static Object[][] readExcel(String filepath, String sheetName) throws InvalidFormatException, IOException {
        FileInputStream file = new FileInputStream(filepath);
        XSSFWorkbook wb = new XSSFWorkbook(file);
        XSSFSheet sheet = wb.getSheet(sheetName);
        int rowCount = sheet.getLastRowNum();
        int column = sheet.getRow(0).getLastCellNum();
        Object[][] data = new Object[rowCount][column];
        for (int i = 1; i <= rowCount; i++) {
            XSSFRow row = sheet.getRow(i);
            for (int j = 0; j < column; j++) {
                XSSFCell cell = row.getCell(j);
                DataFormatter formatter = new DataFormatter();
                String val = formatter.formatCellValue(cell);
                data[i - 1][j] = val;
            }
        }
        wb.close();
        return data;
    }
public static Object[][]readExcel(字符串文件路径,字符串sheetName)引发InvalidFormatException,IOException{
FileInputStream文件=新的FileInputStream(filepath);
XSSF工作簿wb=新XSSF工作簿(文件);
XSSFSheet sheet=wb.getSheet(sheetName);
int rowCount=sheet.getLastRowNum();
int column=sheet.getRow(0.getLastCellNum();
对象[][]数据=新对象[行计数][列];

对于(int i=1;i)为什么您对maven插件注释、maven插件api有依赖关系?对不起,是另一个“解决方案”的遗留问题我尝试过-从Open surefire插件的配置中删除了这些依赖项,maven surefire插件包含
intputEncoding
outputEncoding
,但它们不存在…还可以详细解释您所说的
TestNG不能正确读取某些字符是什么意思…
因为TestNG本身不能读取文件如果…只有您的测试代码可以…我认为这似乎是Excel单元格格式的问题。如果您可以在Excel cam中设置格式,解决问题为什么您依赖maven插件注释、maven插件api?对不起,是另一个“解决方案”的遗留问题我尝试过-从Open surefire插件的配置中删除了这些依赖项,maven surefire插件包含
intputEncoding
outputEncoding
,但它们不存在…还可以详细解释您所说的
TestNG不能正确读取某些字符是什么意思…
因为TestNG本身不能读取文件若…只有你们的测试代码可以…我想这似乎是Excel单元格格式的问题。若你们能在Excel中设置格式,可以解决这个问题
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>NAV_Integration</groupId>
  <artifactId>NAV_Integration</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>NAV_Integration</name>
  <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.version>3.6.0</maven.compiler.version>
        <selenium.version>3.14</selenium.version>
        <testng.version>6.9.10</testng.version>
    </properties>

    <dependencies>  
        <dependency>                
            <groupId>org.seleniumhq.selenium</groupId>                              
            <artifactId>selenium-java</artifactId>                              
            <version>3.14.0</version>                               
        </dependency>                                       
        <dependency>                
            <groupId>org.testng</groupId>                               
            <artifactId>testng</artifactId>                             
            <version>6.9.10</version>                               
            <scope>test</scope>                         
       </dependency>
        <dependency>                
            <groupId>org.apache.poi</groupId>                               
            <artifactId>poi</artifactId>                                
            <version>4.1.0</version>                            
        </dependency>   
        <dependency>                
            <groupId>org.apache.poi</groupId>                               
            <artifactId>poi-ooxml</artifactId>                              
            <version>4.1.0</version>                                
        </dependency>       
    </dependencies>

    <build>
        <plugins>   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <inputEncoding>UTF-8</inputEncoding>
                    <outputEncoding>UTF-8</outputEncoding>
                    <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>