Reading Test data from excel file in Selenium-Cucumber-Java

1,900 views
Skip to first unread message

sachin bhangade

unread,
May 20, 2016, 10:44:26 AM5/20/16
to webdriver
How can we read test data from excel file in Selenium-Cucumber-Java

David Patterson

unread,
May 20, 2016, 12:36:12 PM5/20/16
to webd...@googlegroups.com
There is an Apache project called POI that has code to allow reading or writing Microsoft Office files. I've used it to read Excel or Word files with no problem.

It is pretty easy to use. For an Excel file, you can iterate through the rows and then iterate across the columns.

Dave Patterson

On Wed, May 18, 2016 at 5:06 AM, sachin bhangade <sachinb...@gmail.com> wrote:
How can we read test data from excel file in Selenium-Cucumber-Java

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at https://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.

Dmitri Tikhanski

unread,
May 28, 2016, 7:12:50 AM5/28/16
to webdriver
I would go for Apache Tika. Given you have tika-app.jar in your classpath you can read Excel files like:

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;


InputStream in = new FileInputStream("path to excel file");
Workbook wb = new XSSFWorkbook(in);
in.close();
Sheet sheet1 = wb.getSheet("Sheet1");
Row row = sheet1.getRow(0);
Cell a1 = row.getCell(0);
String a1Value = a1.getStringCellValue();

The above code is slightly adapted version from How to Extract Data From Files With JMeter article. 

More examples:




punkaaj chavaan

unread,
Jun 2, 2016, 12:36:21 AM6/2/16
to webdriver
Check out this link
Reply all
Reply to author
Forward
0 new messages