我试着在这上面使用for循环来从数据表中循环,但它只读了一行,不知道我在哪里做错了什么?
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)
}
}
发布于 2015-06-12 14:41:24
从testRunner.gotoStep(0)
的API documentation
将此TestRunner的执行转移到TestCase中具有指定索引的TestStep
在索引步骤之后,将继续执行。您可能希望它返回到您的循环,这是不正确的!
你的意思可能是:curTC.getTestStepAt(0).run(context.testRunner, context)
;API documentation。
发布于 2015-06-12 15:16:08
您提供的excel文件也可能有问题。我相信XSSFFormulaEvaluator只适用于老式的*.xls excel格式。如果你输入的是*.xlsx格式的excel文件,这可能是一个问题。
在SoapUI NG Pro中有一个DataSource测试步骤,它只允许您指向一个文件(xls或xlsx)并输入数据http://www.soapui.org/data-driven-tests/functional-tests.html
https://stackoverflow.com/questions/30805319
复制相似问题