How to stop and start a for loop

I create the framework for our project,

BEFOREMETHOD (reads the first line 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 for each test method is the BeforeMethod method, which is executed first the first time, my question is: I read the first line from Excel, I put it in the Before method (I need it in the testing method), for the second line from Excel I want to read to perform the second test method, how can I achieve this?

If there is another way how to use different loops, please help me.

+4
source share
1 answer

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);

     }
        }

(PS: !):

@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);
    }
}

, CellContent String. , CellContent String.

, :

@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);
        }
    }
0

Source: https://habr.com/ru/post/1629155/


All Articles