首页 > 解决方案 > 如何从 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]) 

        } 
    }



标签: javagroovyapache-poisoapui

解决方案


正如 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

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


推荐阅读