如何从 excel 获取整数值并存储在 Soap UI 属性步骤中



我在 excel 中有一个保存数值的数据,当我将相同的值从 Excel 发送到 Soap UI 属性时,它的值被转换为字符串,如下所示:

在 Excel 中: 数据列的值为 200 在 Soap UI 属性中: "数据"字段的值将更改为 200.0

任何人都可以帮助我在 Soap UI 属性中获取相同的数值吗?

FileInputStream fis = new FileInputSTream("Excel File Location");
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet Sheet = new XSSFSheet("SheetName");
int totalRows = sheet.getPhysicalNumberOfRows();
testRunner.testCase.SetPropertyvalue("totalRows",totalRows.toString())
def int totalcolumn = sheet.getrow(0).getLastCellNum();
def columns = []
def data = []
def rowIndex = testrunner.testCase.getPropertyValue("RowIndex").toInteger();
if(rowIndex<totalRows)
{
for(int i = 0;i<totalcolumn;i++)
{
colData = sheet.getRow(0).getCell(i).toString();
propdataarray.add(colData)
testData = sheet.getRow(rowIndex).getCell(i).toString();
dataArray.add(testData);
testRunner.testCase.getTestStepByName("Properties").setPropertyValue(columns.get[i],data.get[i]) 
} 
}

正如 Axel Richter 所说,使用DataFormatter.formatCellValue从源头更正值。或者你可以使用一个抽象脚本,它与Groovy配合得很好,为你处理这个问题。

正如你所说,SoapUI 只对属性值使用字符串。如果你想在接收/使用端纠正它,你可以使用这个:

def propVal = '200.0'
assert propVal instanceof java.lang.String
println propVal.toFloat().toInteger()
assert propVal.toFloat().toInteger() instanceof java.lang.Integer

通常最好在源中更正格式(在将其存储在属性中之前(。

最新更新