There are lots of thing you need to understand and implement.
1st: are you going to use excel with extenion .xls or .xlsx. If any of them then use the Apache POI jar to read data from excel.
Apache POI majorly have 2 components
- XSSF : which is for .xlsx extension file.
- HSSF : which is for .xls extension file.
Now Create a new function using both object(XSSF and HSSF). Function will be like :
public List< Map<String, String>> getExcelDataHSSF(int startRowNo, int EndRowNumber){}
public List< Map<String, String>> getExcelDataXSSF(int startRowNo, int EndRowNumber){}
This function will return your data in List of Map object. Where Map's key is columnName and Value is: your test data respective to column.
Now, You need to write a function which check the extension of excel file and execute the function
if extension is .xlsx then run function getExcelDataXSSF(1,20) else getExcelDataHSSF(1,20)
.
After that, Go to your Test file and use TestNG dataprovider to fetch data using above function and pass to you test cases.