0

我在 testNG 测试用例中使用了@Dataprovider,我需要做的是从 excel 中获取数据并在测试中需要的任何地方使用该数据。

@DataProvider(name="productdata")
public Object[][] productdata(){
    Object[][] objectarray=getExcelData("C:/Documents/New Microsoft Excel Worksheet (3).xls","sheet1");
    objectarray[0][0]="p";
    objectarray[0][1]="url";
    objectarray[0][2]="size";

}
//Reading excel sheet value
    @SuppressWarnings({ "null", "resource" })
    public String[][] getExcelData(String s2pproductprices, String sheet1) {
        String[][] arrayExcelData = null;
        try {
            String Filepath = "C:/Documents and Settings/saalam/Desktop/Excel sheets/New Microsoft Excel Worksheet (3).xls";
             FileInputStream file = new FileInputStream(Filepath); 
                HSSFWorkbook hw = new HSSFWorkbook(file);
                 HSSFSheet sheet = hw.getSheet("sheet1"); 

            for (int i= 1 ; i < sheet.getLastRowNum(); i++) {

                for (int j=0; j < 4; j++) {
                    arrayExcelData[i-1][j] = sheet.getRow(i).getCell(j).getStringCellValue();
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
            e.printStackTrace();
        } 
        return arrayExcelData;
    }

我已经运行了这个 testng 测试用例,但它给了我如下错误:

[TestNG] 运行:C:\Documents\testng-eclipse--1785696757\testng-customsuite.xml

配置失败:@AfterTest

在错误中看到的路径与代码中提供的路径不匹配。谁能建议我如何做到这一点,或者我必须提供@parameters。

4

0 回答 0