Data driven testing from Excel with multiple data type

48 views
Skip to first unread message

Sujith C S

unread,
Jul 6, 2016, 4:40:24 PM7/6/16
to testng...@googlegroups.com
Hi Team,

Can any one help to read and save data from an excel into @dataProvider.
Excel has multiple columns and rows with (int, String, float etc), each execution need data from each row.

Currently I was using below , but it is returning only String

public static String getCellData(int RowNum, int ColNum) throws Exception {

try{

Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);

int dataType = Cell.getCellType();

if  (dataType == 3) {

return "";

}else{

String CellData = Cell.getStringCellValue();

return CellData;

}}catch (Exception e){

System.out.println(e.getMessage());

throw (e);

}


⇜Krishnan Mahadevan⇝

unread,
Jul 7, 2016, 3:24:04 AM7/7/16
to testng...@googlegroups.com
You just change your method to start returning back an Object which contains all the data from a row i.e., 

public static TestData getCellData(int RowNum) throws Exception {
//Include your logic that is responsible for reading test data from the Excel sheet here.
}

Here the class TestData is a simple POJO [ Plain Old Java Object] which contains the attributes that represent data for one iteration.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

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

Sujith

unread,
Jul 8, 2016, 10:15:25 AM7/8/16
to testng...@googlegroups.com
Thank you

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages