I am creating framework for our project,
BEFOREMETHOD (reads first row using JXl)
@BeforeMethod
public void Test2() throws BiffException, IOException{
FileInputStream filepath = new FileInputStream("D://Selenium//Project_Stage//AddGroup//inputtoAddGroup.xls");
Workbook wb = Workbook.getWorkbook(filepath);
Sheet sh = wb.getSheet(0);
int totalNoOfRows = sh.getRows();
int rows;
for (rows=1 ; rows < totalNoOfRows;) {
System.out.println("BeforeMethod Executed"+rows);
CellContent1 = sh.getCell(0, rows).getContents().toUpperCase();
System.out.println("CellContent is: "+CellContent1);
CellContent2 = sh.getCell(1, rows).getContents();
CellContent3 = sh.getCell(2, rows).getContents();
CellContent4 = sh.getCell(3, rows).getContents();
CellContent5 = sh.getCell(4, rows).getContents();
rows=rows+1;
}
}
Test methods
@Test(priority=0)
public void Test(){
System.out.println("Test Is Executed1");
if (CellContent1.matches("TRUE")) {
System.out.println("p=0 Cell content is : "+CellContent5);
cells.add(CellContent5);
}
}
What I want is, for each test method there is a BeforeMethod get executed at first right, my question is I have reading first row from Excel I placed it in Before method (I need it in test method), for second row from Excel I want to read to execute second test method how should I achieve that?
If there any other way like using different loops please help me out.
change your iteration to the following:
for (rows = 0 ; rows < totalNoOfRows; rows++) {
for (columns = 0; columns <= 4; columns++){
System.out.println("BeforeMethod Executed "+ rows + " " + columns);
CellContent content =sh.getCell(columns, rows).getContents().toUpperCase();
Test(content);
}
}
and adapt your Test method (PS: method and fieldnames should start with lower case!):
@Test(priority=0)
public void Test(CellContent content){
System.out.println("Test Is Executed");
if (content.matches("TRUE")) {
System.out.println("Cell content is : "+ content);
cells.add(content);
}
}
Also it seems that your object CellContent is a String object. Maybe you could substitute CellContent with String.
If you specificaly want to display the row and column of your cell extend the parameters of your Test method:
@Test(priority=0)
public void Test(CellContent content, int column, int row){
System.out.println("Test Is Executed");
if (content.matches("TRUE")) {
System.out.println("Cell content of cell " + column + "," + row + " is : "+ content);
cells.add(content);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.