我想根据场景中正确/无效的数据将Excel文件中的数据实现到不同的测试中,但是当我想要获得单元格的值时,我得到了"NegativeArraySizeException“。第一行只有一个标题,所以我不想读它,这就是为什么我有参数rows-1的原因。你能指出我的错误在哪里吗?谢谢
public class SignInTest extends Driver {
@BeforeMethod
public void setUp() {
Driver.initConfiguration();
}
public Object[][] getData(String excelPath, String sheetName) {
int rows = excel.getRowCount(sheetName);
int cols = excel.getColumnCount(sheetName);
Object[][] data = new Object[rows - 1][1];
excel = new ExcelReader(excelPath);
for (int rowNum = 1; rowNum < rows; rowNum++) {
for (int colNum = 0; colNum < cols; colNum++) {
data[rowNum - 1][colNum] = excel.getCellData(sheetName, colNum, rowNum);
}
}
return data;
}
@DataProvider(name = "credentials")
public Object[][] getCredentials() {
Object[][] data = getData(excelPath, sheetName);
return data;
}
@Test(dataProviderClass = DataProviders.class, dataProvider = "credentials")
public void loginWithCorrectCredentials(String email, String password) {
HomePageActions hp = new HomePageActions();
SignInActions sign = new SignInActions();
DataProviders dp = new DataProviders();
dp.getData(excelPath, "correctData");
System.out.println("email " + email);
System.out.println("password " + password);
}

发布于 2020-08-12 02:55:22
此函数"excel.getRowCount(sheetName)“
在这一行上:
int rows = excel.getRowCount(sheetName);
返回0(也可能是null),因此当你执行rows 1时,你得到一个小于零的数字。我希望这一点是显而易见的。所以问题就变成了为什么?
故障排除时需要注意的事项:
,会发生什么
我的直觉告诉我,您对工作表的引用有问题,但如果不了解更多关于工作表引用的信息,就不可能确定。
我希望本文中的一些内容能为您指明正确的方向,并让您继续前进。祝好运!
https://stackoverflow.com/questions/63363362
复制相似问题