首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >for循环仅读取一行

for循环仅读取一行
EN

Stack Overflow用户
提问于 2015-06-12 22:19:22
回答 2查看 245关注 0票数 0

我试着在这上面使用for循环来从数据表中循环,但它只读了一行,不知道我在哪里做错了什么?

代码语言:javascript
代码运行次数:0
运行
复制
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)
    }
    }
EN

回答 2

Stack Overflow用户

发布于 2015-06-12 22:41:24

testRunner.gotoStep(0)API documentation

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

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

你的意思可能是:curTC.getTestStepAt(0).run(context.testRunner, context)API documentation

票数 0
EN

Stack Overflow用户

发布于 2015-06-12 23:16:08

您提供的excel文件也可能有问题。我相信XSSFFormulaEvaluator只适用于老式的*.xls excel格式。如果你输入的是*.xlsx格式的excel文件,这可能是一个问题。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30805319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档