Datadriven not working using Testng data provider

◇◆丶佛笑我妖孽 提交于 2020-01-06 05:34:17

问题


I am trying to read data from excel using apache poi with testng data provider but testng is skipping my test method.

Below is the error am getting

SKIPPED: VerifyLoanDetails
java.lang.RuntimeException: java.lang.NullPointerException

Caused by: java.lang.NullPointerException at com.seleniumhybrid.utils.ExcelUtil.getTestdata(ExcelUtil.java:62) at com.seleniumdata.zmartano.LoanDetails.getdata(LoanDetails.java:50)

Below is my class to read data from excel

public class ExcelUtil{

    static Workbook book;
    static Sheet  sheet;
    public static String Testdata_sheet = Constants.path_TestData;



    public static Object  [][] getTestdata(String sheetname) {



        FileInputStream file = null;
        try{
        file = new FileInputStream(Testdata_sheet);
        }
        catch(FileNotFoundException e) {

            e.printStackTrace();
        }


        try {

            book = WorkbookFactory.create(file);
        }
        catch(InvalidFormatException e ) {

            e.printStackTrace();
        }

        catch (IOException e) {

            e.printStackTrace();

        }


        sheet = book.getSheet(sheetname);

        Object [][]data = new Object[sheet.getLastRowNum()][sheet.getRow(0).getLastCellNum()];
        for (int i=0;i<sheet.getLastRowNum();i++) {

            for(int k=0;k<sheet.getRow(0).getLastCellNum();k++) {

                data[i][k]= sheet.getRow(i+1).getCell(k).toString();

            }


        }

        return data;



    }
}

below is my test class to acess the data

public class LoanDetails extends Configreader{



                  WebDriver driver;     

   @BeforeTest
        public  void beforetest() throws Exception { 

                  driver = Browser.GetBrowser();




       }






    @Test(dataProvider = "getdata")

   public  void VerifyLoanDetails(String username) throws Exception {


    driver.findElement(By.xpath(pro.getProperty("account_xpath"))).click();
    driver.findElement(By.xpath(pro.getProperty("username_id"))).sendKeys(username);


    }


    @DataProvider
    public Object[][] getdata(){

        Object data [][] = ExcelUtil.getTestdata("credentials");


        return data;


    }
}

来源:https://stackoverflow.com/questions/52033851/datadriven-not-working-using-testng-data-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!