- Heading
How to get the username and password from excel using cucumber
package com.qa.excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelReader{
// public static void main(String args[]) throws IOException {
//ExcelReader reader=new ExcelReader();
// reader.readExcelData();
// }
public Object[][] readExcelData() throws IOException
{
String Filepath="E:\\Old\\ExtentReports\\ExcelFiles\\login.xlsx";
File file=new File(Filepath);
FileInputStream fis=new FileInputStream(file);
XSSFWorkbook book=new XSSFWorkbook(fis);
XSSFSheet sheet=book.getSheetAt(0);
Object[][] data=new Object[sheet.getLastRowNum()][2];
for(int i=1;i<=sheet.getLastRowNum();i++)
{
for(int j=0;j<sheet.getRow(i).getLastCellNum();j++)
{
Cell cell=sheet.getRow(i).getCell(j);
switch(cell.getCellType()) {
case STRING :
{
data[i-1][j]=cell.getStringCellValue();
}
case NUMERIC:
{
data[i-1][j]=cell.getStringCellValue();
}
default :
{
data[i-1][j]=cell.getStringCellValue();
}
}
}
}
for(int i=0;i<data.length;i++)
{
for(int j=0;j<data[i].length;j++)
{
System.out.println(data[i][j]);
}
}
return data;
}
}
I'm able to get username and password from excel using java but, I'm not understanding how to get the data in step definition in sendkeys
.