Data Driven FrameWork
this concept is being used under Data provider concept, here different set of input datas being fetched from Excel file and feeded to test scenario where different username,password combo testing
using apache poi ooxml
Script:
FileInputStream stream=new FileInputStream(new File(“SAngar.xlsx”));
WorkBook workbook=new XSSFWorkBook(stream);
Sheet sheet=workBook.getSheet(0) or getSheet(“Sheet1”);
int rowcount=sheet.getPhysicalNumberOfRows();
int cellCount=sheet.getRow(0).getPhysicalNumberOfCells();
String[][] set=new String[rowCount-1][cellCount];
for(int i=1;i<rowCount;i++){
Row row=sheet.getRow(i);
for(int j=0;j<cellCount;j++){
Cell cell=row.getCell(j);
set[i-1][j]=cell.toString();
}}
Using Data provider:
@ DataProvider(name=”sangar”)
public Object[][] getData(){
return new Object[][] {{“sangar”,”another”},
{“New way”,”si another”},{“kumar”,”Ayyan”}.{“SAngar”,”nsjd”}};
sometimes
return getExcelData();
}
public String[][] getExcelData(){
FileInputStream stream=new FileInputStream(new File(“Sangar..xlsx”));
WorkBook workBook=new XSSFWorkBook(stream);
FormulaEvaluator evaluator=workBook.getCreationHelper().createFormulaEvaluator();
Sheet sheet=workbook.getSheet(“Sheet1”);
int rowCount=sheet.getPhysicalNumberOfRows();
int columnCount=sheet.getRow(0).getPhysicalNumberOfCells();
String[][] data=new String[rowCount-1][columnCount];
for(int i=1;i<rowCountli;i++):
Row row=row.getCell(i);
for(int j=0;j<columnCount;j++){
Cell cell=row.getCell(j);
Celltype cellType=cell.getCellType();
Switch(cellType):
case STRING:
data[i-1][j]=cell.getStringCellValue();
case NUMERIC:
if(DateUtil.isCellDateFormetted(cell)){
Date date=cell.getDateCellValue();
SimpleDateFormat format=new SimpleDateFormat(“EEE,MMM d,' 'yy”);
data[i-1][j]=format.format(date).toString();
}else{
int value=cell.getNumericCellValue();
data[i-1][j]=String.valueOf(value);
}}}
Case FORMULA:
CellValue cellValue=evaluator.evaluate(cell);
if(cellValue.getCellType()==CellType.STRING):
data[i-1][j]=cellValue.getStringValue();
else if(cellValue.getCellType()==CellType.NUMERIC)
data[i-1][j]=cellValue.getNumberValue();
else if(cellValue.getCellType()==CellType.BOOLEAN)
data[i-1][j]=cellValue.getBooleanValue();
Comments
Post a Comment