- karthik palicherla
- Posts : 2
Join date : 2015-01-29
how to print row wise data executing all @test methods for each row in excel sheet
Tue Sep 29, 2015 6:40 pm
package DataProvider;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
public class Sample
{
@Test ( priority=0)
public void borrowerObligation() throws InterruptedException, IOException
{
FileInputStream file1 = new FileInputStream(new File("D://Users//kpaliche//Desktop//Selenium//Sample1.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file1);
HSSFSheet sheet4 = workbook.getSheetAt(0);
int rowcount=sheet0.getLastRowNum();
System.out.println("sheet0 :"+rowcount);
for (int i=1 ; i <= rowcount ; i++){
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(0).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(1).getNumericCellValue())));
System.out.println(sheet4.getRow(1).getCell(2).getStringCellValue());
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(3).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(4).getNumericCellValue())));
}} // @Test ( priority=0)
@Test ( priority=1)
public void financials() throws InterruptedException, IOException
{
FileInputStream file1 = new FileInputStream(new File("D://Users//kpaliche//Desktop//Selenium//Sample1.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file1);
HSSFSheet sheet1 = workbook.getSheetAt(1);
int rowcount=sheet1.getLastRowNum();
System.out.println("sheet1 :"+rowcount);
for (int i=1 ; i <= rowcount ; i++){
System.out.println(sheet1.getRow(1).getCell(0).getStringCellValue());
System.out.println(new SimpleDateFormat("MM/dd/yyyy").format(sheet1.getRow(1).getCell(1).getDateCellValue()));
System.out.println(String.valueOf(Math.round(sheet1.getRow(1).getCell(2).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet1.getRow(1).getCell(3).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet1.getRow(1).getCell(4).getNumericCellValue())));
}}
}
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.openqa.selenium.By;
import org.testng.annotations.Test;
public class Sample
{
@Test ( priority=0)
public void borrowerObligation() throws InterruptedException, IOException
{
FileInputStream file1 = new FileInputStream(new File("D://Users//kpaliche//Desktop//Selenium//Sample1.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file1);
HSSFSheet sheet4 = workbook.getSheetAt(0);
int rowcount=sheet0.getLastRowNum();
System.out.println("sheet0 :"+rowcount);
for (int i=1 ; i <= rowcount ; i++){
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(0).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(1).getNumericCellValue())));
System.out.println(sheet4.getRow(1).getCell(2).getStringCellValue());
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(3).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet4.getRow(1).getCell(4).getNumericCellValue())));
}} // @Test ( priority=0)
@Test ( priority=1)
public void financials() throws InterruptedException, IOException
{
FileInputStream file1 = new FileInputStream(new File("D://Users//kpaliche//Desktop//Selenium//Sample1.xls"));
HSSFWorkbook workbook = new HSSFWorkbook(file1);
HSSFSheet sheet1 = workbook.getSheetAt(1);
int rowcount=sheet1.getLastRowNum();
System.out.println("sheet1 :"+rowcount);
for (int i=1 ; i <= rowcount ; i++){
System.out.println(sheet1.getRow(1).getCell(0).getStringCellValue());
System.out.println(new SimpleDateFormat("MM/dd/yyyy").format(sheet1.getRow(1).getCell(1).getDateCellValue()));
System.out.println(String.valueOf(Math.round(sheet1.getRow(1).getCell(2).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet1.getRow(1).getCell(3).getNumericCellValue())));
System.out.println(String.valueOf(Math.round(sheet1.getRow(1).getCell(4).getNumericCellValue())));
}}
}
- murthiActive particpant
- Posts : 11
Join date : 2016-04-14
Location : Bangalore
Re: how to print row wise data executing all @test methods for each row in excel sheet
Fri Apr 15, 2016 8:35 pm
You can use data providers. Then Iterate throw each row....
Permissions in this forum:
You cannot reply to topics in this forum