Selenium : How to read excel file using java ?

It is very common requirement reading test data from the excel file when you do any automation project in selenium, very simple use case is testing login functionality by passing different user credentials but, here I am not going to test login functionalities instead of that I am testing search functionality by passing different keywords

Step 1: Create project

First thing is we need to do is create a new maven project, if you don’t know how to create a project then refer my other article on creating maven project or you can create a simple java project and convert it into maven project

Step 2: Add apache poi dependency

We are going to use Apache POI library to read data from the excel file so, once the project is created, open the pom.xml file and add below dependency

Step 3: Read excel data




Create a new class and add the below code this helper class helps us to read excel data and also it contains several helper methods, you can use it to read row data or cell data etc…  

Step 4: Test search functionalities

Create a new TestNG class and add below code it reads the data from the excel sheet and pass it as an input parameter to the search textbox, upon clicking on search button it will redirect to the search results page 

Download code