使用 KeywordDriven 从 Excel 文件中获取数据时遇到执行测试用例的问题

Encountered problem to perform test case when fetching data from Excel file using KeywordDriven

我面临的问题是库未像 WorkbookRowCellHSSFWork 等那样导入。当我尝试导入时,它没有导入。

这里是 link 控制台:https://prnt.sc/15oajs9

 public class ReusableFunction {
    WebDriver driver;
    public  String [][] fetchDataFromExcel() {
        Workbook wb = null;
        String [][] data= null;
        try {
            String path = fetchprop("KEYWORD_PATH");
            File excel = new File(path);
            FileInputStream file  = new FileInputStream(excel);
            
            System.out.println(path);
            String extn = path.substring(path.indexOf(".")+ 1);
            System.out.println(extn);
            if (extn.equals("xlsx")) {
                wb = new XSSFWorkbook(file);
            } else {
                wb = new HSSFWorkbook(file);
            }
            Sheet sheet = wb.getSheet("Sheet1");
            
            int rownum = sheet.getLastRowNum();
            System.out.println("Rows: " + rownum);
            
            int column = sheet.getRow(0).getLastCellNum();
            
            data  = new String [rownum][column];
            
            for (int i =0; i < rownum; i++) {
                Row row = sheet.getRow(i);
                for (int j =0;  j < column; j++) {
                    Cell cell = row.getCell(j);
                    String value = cell.toString();
                    data[i][j] =  value;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                wb.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
        return data;
    }`

谁能知道我们如何解决这个问题

在您的 pom.xml 文件中添加这些依赖项:

poi

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.0.0</version>
</dependency>

poi-oxml :

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.0.0</version>
</dependency>

commons-collections :

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.4</version>
</dependency>

commons-compress :

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-compress</artifactId>
    <version>1.20</version>
</dependency>

xmlbeans

<!-- https://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans -->
<dependency>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
    <version>5.0.0</version>
</dependency>

dom4j

<!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
<dependency>
    <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
    <version>1.6.1</version>
</dependency>

构建您的项目,然后 运行,应该适合您。