0

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;
}
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • `"H:/JAVA TESTING CODES/UIAutomation/src/main/java/com/test/automation/UIAutomation/data" +workbookname;` Assuming `data` is a folder, don't you need a trailing `/`? – The Archetypal Paul Sep 25 '17 at 15:29
  • I tried with trailing / but there is a same error –  Sep 25 '17 at 15:40
  • Please provide much more detail. Which line gives the error, for instance. What are the values passed to the function that gives the error etc? This seems something that is quite easily debuggable by yourself - I don't think there's anything tricky that means [SO] questions are the best way of solving it. – The Archetypal Paul Sep 25 '17 at 15:42
  • String[][] data = excel.getDataFromSheet(workbookname, sheetname); from test base –  Sep 25 '17 at 15:47
  • String[][]testRecords = getData("TestData.xlsx","LoginTestData"); from my script file –  Sep 25 '17 at 15:47
  • ] com.test.automation.UIAutomation.Homepage.TC003_VerifyLoginWithDifferentRecords.getTestData() must return either Object[][] or Iterator[], not class [[Ljava.lang.String; here is a brief error that came after debugging –  Sep 25 '17 at 16:00

1 Answers1

0

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

Akash
  • 115
  • 2
  • 13