Write into excel at runtime during test execution

tod2020@mail.ru said:

@discover.selenium said:

Hi Sandeep, You have to use custom keyword to write into excel.

And how looks the code?

You could create a custom keyword with the code as the example below:


@Keyword
def void writeToExcel(String text ){
	FileInputStream file = new FileInputStream (new File("D:\\Testdata.xlsx"))
	XSSFWorkbook workbook = new XSSFWorkbook(file);
	XSSFSheet sheet = workbook.getSheetAt(0);
	Cell searchText = sheet.getRow(1).getCell(1);
	searchText.setCellValue(text);
	file.close();
	FileOutputStream outFile =new FileOutputStream(new File("D:\\Testdata.xlsx"));
	workbook.write(outFile);
	outFile.close();
}
2 Likes