Data Driven Testing in Selenium WebDriver Using jxl

Data Driven Testing through Selenium WebDriver using jxl

1- Download jxl jar file and add it in to path
2- Junit jar file
3- Selenium-server-standalone-2.x.jar
Add these three jar file in build path and to read more about adding jar file read my last post Configuring Selenium Webdriver in Eclipse with Testng plugin installation .

In general when we say Data Driven then only thing that should come in to mind is that input is going to be read from some xls file, xml,csv or some other table oriented file and might be output would also be written in xls,xml or csx file. All read data from various files are stored in variables and finally used by scripts to run the test cases.
Data Driven testing is mainly divided in two part
1- Reading data and storing in to variable
2- Using data stored in variable in to some generic script.

Reading Data and storing in to variable
Since Webdriver don’t have structure like other automation tools like QTP to have its own Data table to store data to run tests in Data Driven framework. So we normally two jar file(Binaries) JXL(Java Excel API) and Apache POI to make Data Driven test framework for  WebDriver.
I am using JXL binary in this example. so for reading data from xls file we need to follow these step

1- Opening Excel file , so to open excel file we would use these two line. I have created one excel file r.xls and now we would write code to reach to this file and to open this excel sheet.
import jxl.Workbook;

FileInputStream fi = new FileInputStream(“C:\Users\kaushal\Desktop\r.xls”);

Workbook w = Workbook.getWorkbook(fi);

In above code
FileInputStream obtains input bytes from a file in a file system

2- Opening worksheet

import jxl.Sheet;

Sheet sh = w.getSheet(0); or w.getSheet(Sheetnumber)

Here 0 as argument states about firest sheet, if we want to read second sheet then we may use 1 in place of 0

3- Reading data
code used is 

String variable1 = s.getCell(column, row).getContents();

These are 3 steps that is used in reading data from excel sheet

In my example or code I am going to write code to test login to Gmail for various user and Username and Password is save in excel sheet and we will keep reading this data by using loop and we would store these data in two variable username and password