Friday, 2 February 2018

JXL: How to Read the Input in Excel-Read and Write Concept Using Selenium Tool

JXL: 

It is a data Driven Testing to test the Element with Multiple inputs

It support .xls file format

There is two operations in that Read and write concepts


write:                                                                                      Read:

WritableWorkbook---------------classname--------------------Workbook
createWorkbook----------------methodname-----------------getWorkbook
 createSheet-------------------methodname---------------------getSheet
WritableSheet--------------classname--------------------------Sheet
Label---------------classname                                      getcell.getcontents(read input in row and col)
addCell-----------------methodname                            close--->methodname
write----------methodname
close------------methodname


Write Program: 

In the write program to create a Excel,Sheet and pass the Inputs Automatically.

public class write {
public static void main(String[] args) throws IOException, RowsExceededException, WriteException {

WritableWorkbook wb=Workbook.createWorkbook(new File("d:\\driver\\test.xls"));
WritableSheet sh=wb.createSheet("anandh", 0); //("sheetname",sheetindex)
WritableSheet sh1=wb.createSheet("sathish", 1);
Label d=new Label(0,0,"selenium"); //(column,row,"inputs")
Label d1=new Label(1,2,"testing");
Label d2=new Label(0,0,"selenium");
Label d3=new Label(1,2,"testing");
sh.addCell(d);
sh.addCell(d1);
sh1.addCell(d2);
sh1.addCell(d3);
wb.write();
wb.close();
}


Read Program: 

In the Read Program to read the Inputs in Excel,Sheet and in the particular row and column.

public class read {
public static void main(String[] args) throws BiffException, IOException, InterruptedException {
// TODO Auto-generated method stub
Workbook wb=Workbook.getWorkbook(new File("d:\\driver\\data.xls"));
Sheet e=wb.getSheet(0);
for(int i=1;i<=2;i++)
{
WebDriver d=new FirefoxDriver();
d.manage().window().maximize();
d.get("URL");
d.findElement(By.id("Email")).sendKeys(e.getCell(0,i).getContents());
d.findElement(By.id("next")).click();
Thread.sleep(3000);
d.findElement(By.id("Passwd")).sendKeys(e.getCell(1,i).getContents());
d.findElement(By.id("signIn")).click();
d.close();
}
}


Note:  in the Jxl it read the inputs in col,row

e.getCell(0,i).getContents()

0--->column
i--->Row

No comments:

Post a Comment