for循环只读一行

时间:2015-06-12 14:19:22

标签: groovy soapui

即时尝试使用循环来从数据表循环,但它只读了一行,不知道我在哪里做错任何想法?

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 个答案:

答案 0 :(得分:0)

来自testRunner.gotoStep(0)的{​​{3}}:

  

使用TestCase中指定的索引将此TestRunner的执行转移到TestStep

索引步骤后将继续执行。您可能期望它会返回到您的循环,这是不正确的!

你可能意味着:curTC.getTestStepAt(0).run(context.testRunner, context); API documentation

答案 1 :(得分:0)

您提供的excel文件也可能存在问题。 XSSFFormulaEvaluator我相信只适用于旧式* .xls excel格式。如果您正在提供* .xlsx格式的Excel文件,则可能会出现问题。

在SoapUI NG Pro中,有一个DataSource测试步骤,它只允许您指向文件(xls或xlsx)并输入数据 http://www.soapui.org/data-driven-tests/functional-tests.html