0

这是我的脚本代码。我正在尝试从 excel 表中提取数据,但是在读取 xlxs filenull 时出现错误提示异常

public class TC003_VerifyLoginWithDifferentRecords extends testbase {

    public static final Logger log = 
    Logger.getLogger(TC003_VerifyLoginWithDifferentRecords.class.getName());
    HomePage homepage;

    @DataProvider(name = "logindata")
    public String[][] getTestData()
    {
        String[][]testRecords = getData("TestData.xlsx","LoginTestData");   
        return testRecords;
    }

    @BeforeClass
    public void setUp()
    {
        init();
    }

    @Test(dataProvider = "logindata")
    public void TestLogin(String emailAddress, String Password)
    {
        log.info("================Starting VerifyLogin with Different 
        Records===================");
        homepage = new HomePage(driver);
        homepage.loginApplication(emailAddress,Password);
        log.info("================Ending VerifyLogin with Different Records===================");
    }

    @AfterTest
    public void endTest()
    {
        // driver.close();
    }

这是 mt testbase 类,我在其中提供了 excel 表的路径

public String[][] getData(String workbookname, String sheetname)
{

    String path = "H:/JAVA TESTING CODES/UIAutomation/src/main/java/com/test/automation/UIAutomation/data"+workbookname;
    excel = new ExcelReader(path);
    String[][] data = excel.getDataFromSheet(workbookname, sheetname);
    return data;
}
4

1 回答 1

0

我也面临同样的问题,但是在我的 excel 中,我检查了以下 3 点。

1) 如果您不使用 Microsoft 产品 excel,请在 Excel_reader 类中的任何地方使用 HSSF 类。2) 您必须使用 Excel 选项(例如 Change to TEXT to Columns)将所有数据转换为 Excel 中的字符串格式。3)您的工作表应该与您在函数中作为参数传递的名称完全相同,例如 LoginTestData 在您的情况下,工作簿名称也应该与函数中提供的 TestData.xlsx 名称相同

检查以上 3 点并让我知道问题是否仍然存在,因为我已经完成了与您所做的相同的编码,但考虑了以上 3 点并且它有效

于 2018-01-31T12:10:42.370 回答