Exception in reading Xlxs filenull

134 Views Asked by At

This is my script code. i am trying to extract data from excel sheet but there is an error saying exception in reading 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();
    }

This is mt testbase class where i have provided path of the excel sheet

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;
}
1

There are 1 best solutions below

0
On

I was also facing the same issue but then In my excel I checked the below 3 points.

1) If you are not using Microsoft product excel then please use HSSF classes everywhere in your Excel_reader class. 2) You have to convert all your data to to String format in excel by using excel options like Change to TEXT to Columns. 3) Your sheet should exactly the same name which you are passing as an argument in your function like LoginTestData in your case, also Workbook name should be having TestData.xlsx the same name as provided in the function

check with the above 3 points and let me know if issue still persists, because i have done the same coding like you have done but with above 3 points taken into consideration and it worked