Error in Data Driven Framework

Answered

Hi,
I am working on Data Driven Framework example shown in Selenium WebDriver Tutorials in  www.toolsqa.com  website. When I run Apache_POI_TC.java file, I am getting the following error:

Exception in thread “main” java.io.FileNotFoundException: C:\Users\ABK\Desktop\Sama\Eclipse\OnlineStore\src\testData (Access is denied)

Appreciate if anyone could help me out with this error.

on November 4, 2014.
Add Comment
  • 4 Answer(s)
    Best answer

    Hi,

    It seems like you have not imported all the apache POI files to the project.

    RE: Error in Data Driven Framework

    Associate the jars given in the ooxml-lib folder and lib folder also apart from the root folder jars. Insite ooxml-lib folder you will get xml-beans jars for which you are getting error.

    Regards,

    Lakshay Sharma

    Professor Answered on November 5, 2014.
    Add Comment

    Hi,

    Make sure the Excel file is closed. Make sure that Excel file is not corrupted, try opening it. Make sure the location is correct, as I see the path is till testData folder, it did not display the excel file name after it, make sure you place the slash after testData folder.

    Regards,
    Lakshay Sharma

    Professor Answered on October 30, 2014.
    Add Comment

    The above error is fixed. I am getting a different error. As I am a beginner in Java programming and Selenium, I have difficulty in understanding the errors. Appreciate if you could help me out.

    Here is the following error message:

    Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject

    at utility.ExcelUtils.setExcelFile(ExcelUtils.java:25)

    at automationFramework.Apache_POI_TC.main(Apache_POI_TC.java:18)

    Here is the code:

    Apache_POI_TC.java

    package automationFramework;
        import java.io.IOException;
        import java.util.concurrent.TimeUnit;
        import org.openqa.selenium.WebDriver;
        import org.openqa.selenium.firefox.FirefoxDriver;
        import pageObjects.*;
        import utility.ExcelUtils;
        import utility.Constant;
        import appModules.SignIn_Action;
            
        public class Apache_POI_TC {
        public static void main(String[] args) throws Exception {
            ExcelUtils.setExcelFile(Constant.Path_TestData + Constant.File_TestData,"Sheet1");
            WebDriver driver = new FirefoxDriver();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.get(Constant.URL);
            SignIn_Action.Execute(driver);
            System.out.println("Login Successful, now its the time to Log Off Buddy");
            Home_Page.User_Account(driver).click();
            Home_Page.Sign_out(driver).click();
            driver.quit();
            ExcelUtils.setCelldata("Pass", 1, 3);
            }
        }
    

    ExcelUtils.java

    package utility;
            import java.io.FileInputStream;
            import java.io.FileNotFoundException;
            import java.io.FileOutputStream;
            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;
        public class ExcelUtils {
            private static XSSFSheet ExcelWSheet;
            private static XSSFWorkbook ExcelWBook;
            private static XSSFCell Cell;
            private static XSSFRow Row;
        public static void setExcelFile(String Path, String SheetName) throws Exception{
            try{
                FileInputStream ExcelFile = new FileInputStream(Path);
                ExcelWBook = new XSSFWorkbook(ExcelFile);
                ExcelWSheet = ExcelWBook.getSheet(SheetName);
            } catch(Exception e){
                throw(e);
                }
            }
            
        public static String getCellData(int RowNum, int ColNum){
        try{
            Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
            String CellData = Cell.getStringCellValue();
            return CellData;
        }catch(Exception e){
            return"";
            }
        }
        
        public static void setCelldata(String Result, int RowNum, int ColNum) throws Exception{
            try{
                Row = ExcelWSheet.getRow(RowNum);
                Cell = Row.getCell(ColNum, Row.RETURN_BLANK_AS_NULL);
                if(Cell == null){
                    Cell = Row.createCell(ColNum);
                    Cell.setCellValue(Result);
                }else{
                    Cell.setCellValue(Result);
                    }
                FileOutputStream fileOut = new FileOutputStream(Constant.Path_TestData + Constant.File_TestData);
                ExcelWBook.write(fileOut);
                fileOut.flush();
                fileOut.close();
            }catch(Exception e){
                throw(e);
                }
            }
        }
    
    Train Answered on November 4, 2014.
    Add Comment

    Thank you so much Lakshay. The issue has been resolved.

    Train Answered on November 5, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.