我正在尝试编写一个代码来自动使用Appium进行移动网站测试。我需要阅读Excel的数据。我正在将项目写为Maven代码。从Maven存储库中可以采取什么?
nb:我是Java的新手和任何类型的自动化。
您应该使用jxl或poi jar文件读取来自Excel的数据,它还提供Maven依赖项
您可以使用poi。
在pom.xml
中添加依赖关系<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
在您的项目中添加一个实用程序类,如下所示:确保您获得表格名称(在课堂中)正确
package com.appium.utils;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.util.POILogger;
import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
public class ExcelDriven {
public static XSSFWorkbook wb;
public static XSSFSheet sheet;
public static XSSFRow row;
public static XSSFCell cell;
public static FileInputStream fis;
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// fis = new FileInputStream("/Users/tabish/Downloads/data.xlsx");
}
public static String getCellData(int rownum,int col, String fileName)
{
try {
fis = new FileInputStream("/path/to/file/"+fileName+".xlsx");
wb = new XSSFWorkbook(fis);
sheet= wb.getSheet("Sheet1");
row = sheet.getRow(rownum);
cell = row.getCell(col);
// System.out.println(cell.getStringCellValue());
if (cell==null){
return "";
}
return cell.getStringCellValue();
}
catch (Exception e)
{
System.out.println("In the Catch Block:"+e);
return "Exception Occured";
}
}
}
加速数据
while (!ExcelDriven.getCellData(0,i,"fileName").equals(""))
{
SomeClass.SomeMethod(ExcelDriven.getCellData(0,i,"fileName"));
i++;
}