How to send rows with specific flag to data provider

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to send rows with specific flag to data provider

Kritika Gupta
I have excel sheet with 20 rows and 10 of them are with flag M(Column 0), which I want to pass to data provider to run the test 10 times, that mean I want to run @Test based on the total no. of flag value and to run it as per the corresponding values.
Below is the code I am using but its passing all the rows to data provider and running 20 times.

File filpath = new File(FilePath);

FileInputStream ExcelFile = new FileInputStream(filpath);

// Access the required test data sheet

ExcelWBook = new XSSFWorkbook(ExcelFile);

ExcelWSheet = ExcelWBook.getSheetAt(0);

int startRow = 1;

int startCol = 0;

int ci, cj;

int totalRows = ExcelWSheet.getLastRowNum();//total no. of rows

//System.out.println("total rows in Excel"+ totalRows);

int totalCols = ExcelWSheet.getRow(0).getLastCellNum();

//System.out.println("total columns in Excel"+ totalCols);

tabArray = new String[totalRows][totalCols];

for (int k = 1; k < totalRows;)

{

if(EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M"))

{

System.out.println(k +" "+EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M"));

ci = 0;

for (int i = startRow; i <= totalRows; i++ , ci++) {

cj = 0;

for (int j = startCol; j <totalCols; j++, cj++) {

tabArray[ci][cj] = getCellData(i, j);

System.out.println("total array "+ tabArray[ci][cj]);

}

}

}

}

}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to send rows with specific flag to data provider

Todd Bradley-2
Well, first off, this has nothing to do with TestNG. This is simply a generic program flow logic problem.

You didn’t show in this example what you are returning, so I’m guessing your data provider returns tabArray. If that’s true, the reason your test is running too many times is because you sized tabArray to be the same size as the input table. It doesn’t matter how many rows of tabArray have real data. If it has totalRows rows, then TestNG will run your test totalRows times. 


Todd.



On Tue, Oct 31, 2017 at 4:11 AM Kritika Gupta <[hidden email]> wrote:
I have excel sheet with 20 rows and 10 of them are with flag M(Column 0), which I want to pass to data provider to run the test 10 times, that mean I want to run @Test based on the total no. of flag value and to run it as per the corresponding values.
Below is the code I am using but its passing all the rows to data provider and running 20 times.

File filpath = new File(FilePath);

FileInputStream ExcelFile = new FileInputStream(filpath);

// Access the required test data sheet

ExcelWBook = new XSSFWorkbook(ExcelFile);

ExcelWSheet = ExcelWBook.getSheetAt(0);

int startRow = 1;

int startCol = 0;

int ci, cj;

int totalRows = ExcelWSheet.getLastRowNum();//total no. of rows

//System.out.println("total rows in Excel"+ totalRows);

int totalCols = ExcelWSheet.getRow(0).getLastCellNum();

//System.out.println("total columns in Excel"+ totalCols);

tabArray = new String[totalRows][totalCols];

for (int k = 1; k < totalRows;)

{

if(EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M"))

{

System.out.println(k +" "+EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M"));

ci = 0;

for (int i = startRow; i <= totalRows; i++ , ci++) {

cj = 0;

for (int j = startCol; j <totalCols; j++, cj++) {

tabArray[ci][cj] = getCellData(i, j);

System.out.println("total array "+ tabArray[ci][cj]);

}

}

}

}

}

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--
Sent from Gmail Mobile

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to send rows with specific flag to data provider

Kritika Gupta
Thanks Todd, 

I have solved the problem based on your reply. I used the below logic 

public static Object[][] getTableArray(String FilePath) throws Exception {

String[][] tabArray = null;

try {

File filpath = new File(FilePath);
FileInputStream ExcelFile = new FileInputStream(filpath);

// Access the required test data sheet

ExcelWBook = new XSSFWorkbook(ExcelFile);

ExcelWSheet = ExcelWBook.getSheetAt(0);

int totalRows = ExcelWSheet.getLastRowNum();// total no. of rows

int totalCols = ExcelWSheet.getRow(0).getLastCellNum();// total no. of rows

int countRow = 0;

for (int k = 1; k <= totalRows; k++) {
if (EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M")) {
countRow++;
}
}

tabArray = new String[countRow][totalCols];

int ci = 0;
for (int i = 1; i <= totalRows; i++) {
if (EOTdata.ExcelWSheet.getRow(i).getCell(0).getStringCellValue().equalsIgnoreCase("M")) {

for (int j = 0 ; j < totalCols; j++) {
tabArray[ci][j] = getCellData(i, j);
//System.out.println("total array " +ci +" "+ j +" "+tabArray[ci][j]);
}
ci++;
}
}



On Tue, 31 Oct 2017 at 7:06 PM, Todd Bradley <[hidden email]> wrote:
Well, first off, this has nothing to do with TestNG. This is simply a generic program flow logic problem.

You didn’t show in this example what you are returning, so I’m guessing your data provider returns tabArray. If that’s true, the reason your test is running too many times is because you sized tabArray to be the same size as the input table. It doesn’t matter how many rows of tabArray have real data. If it has totalRows rows, then TestNG will run your test totalRows times. 


Todd.



On Tue, Oct 31, 2017 at 4:11 AM Kritika Gupta <[hidden email]> wrote:
I have excel sheet with 20 rows and 10 of them are with flag M(Column 0), which I want to pass to data provider to run the test 10 times, that mean I want to run @Test based on the total no. of flag value and to run it as per the corresponding values.
Below is the code I am using but its passing all the rows to data provider and running 20 times.

File filpath = new File(FilePath);

FileInputStream ExcelFile = new FileInputStream(filpath);

// Access the required test data sheet

ExcelWBook = new XSSFWorkbook(ExcelFile);

ExcelWSheet = ExcelWBook.getSheetAt(0);

int startRow = 1;

int startCol = 0;

int ci, cj;

int totalRows = ExcelWSheet.getLastRowNum();//total no. of rows

//System.out.println("total rows in Excel"+ totalRows);

int totalCols = ExcelWSheet.getRow(0).getLastCellNum();






//System.out.println("total columns in Excel"+ totalCols);

tabArray = new String[totalRows][totalCols];

for (int k = 1; k < totalRows;)

{

if(EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M"))

{

System.out.println(k +" "+EOTdata.ExcelWSheet.getRow(k).getCell(0).getStringCellValue().equalsIgnoreCase("M"));

ci = 0;

for (int i = startRow; i <= totalRows; i++ , ci++) {

cj = 0;

for (int j = startCol; j <totalCols; j++, cj++) {

tabArray[ci][cj] = getCellData(i, j);

System.out.println("total array "+ tabArray[ci][cj]);

}

}

}

}

}

--
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 [hidden email].

To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--
Sent from Gmail Mobile

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/kO19G9BrJxs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.