for loop only reading one row

278 views Asked by At

im trying use for loop on this to loop from datasheet, but its only reading one row, dont know where i did wrong any Ideas?

import org.apache.poi.xssf.usermodel.*;
    import org.apache.poi.ss.usermodel.DataFormatter

    cellDataFormatter = new DataFormatter()





  //Create formula evaluator


 fEval = new XSSFFormulaEvaluator(context.srcWkSheet.getWorkbook())

    //Increment the rowcounter then read in the next row of items
    RC = context.rowCounter;

    if(RC<=context.srcWkSheet.getLastRowNum()){//Check if we've reached the last row
    for(int i =0;  i < RC;  i++)
    {
        curTC = testRunner.testCase
        sourceRow = context.srcWkSheet.getRow(i)//Get a spreadsheet row

        //Step through cells in the row and populate property data 

        data1Cell = sourceRow.getCell(0)
        curTC.setPropertyValue("data1",cellDataFormatter.formatCellValue(data1Cell ,fEval))

        data2Cell = sourceRow.getCell(1)
        curTC.setPropertyValue("data2",cellDataFormatter.formatCellValue(data2Cell ,fEval))

        data3Cell = sourceRow.getCell(2)
        curTC.setPropertyValue("data3",cellDataFormatter.formatCellValue(data3Cell ,fEval))

        //Rename test cases for readability in the TestSuite log


        curTC.getTestStepAt(0).setName("data1-" + curTC.getPropertyValue("BC"))
        //Go back to first test request with newly copied properties
        testRunner.gotoStep(0)
    }
    }
2

There are 2 answers

3
SiKing On

From the API documentation for testRunner.gotoStep(0):

Transfers execution of this TestRunner to the TestStep with the specified index in the TestCase

Execution will continue after the indexed step. You are probably expecting it will return back to your loop, which is incorrect!

You probably meant something like: curTC.getTestStepAt(0).run(context.testRunner, context); API documentation.

0
user2505885 On

You could also have an issue with the excel file you are providing. XSSFFormulaEvaluator I believe is only for old style *.xls excel format. Could be an issue if you're feeding *.xlsx format excel file.

In SoapUI NG Pro there's a DataSource test step that simply allows you to point to a file (xls or xlsx) and feed in the data http://www.soapui.org/data-driven-tests/functional-tests.html