java - 如何从 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
通常最好在源处更正格式(在将其存储在属性中之前)。
推荐阅读
- javascript - 即使我在 NuxtJS 上做了一些小改动,我是否需要继续上传所有文件
- java - 如何使用 Java Rally API 获取给定缺陷的讨论
- scala - 如何对 Set[ValidatedNel[String, Double]] 求和?
- c# - 在 chrome 控制台中创建 angularjs 多页面应用程序出现以下错误:您拼错了模块名称或忘记加载它
- google-cloud-platform - 存储桶权限
- swift - 方向是向后打开苹果地图
- ruby-on-rails - PATCH 获取 json 主体到 Rails
- h2 - 如何找到 H2 数据库处于哪种兼容模式?
- python - 有没有办法从另一个 jupyter notebook 测试一个 jupyter notebook?
- linkedin - 如何过滤 playableStreams 字段?