我如何将一个参数发送到 rest api,它可以为 null 或有一些值?
How i can send one parameter in to rest api which can be null or have some value?
如何将一个参数发送到 rest api,它可以为 null 或有一些值?
我想用 json 发送这个参数。
数据是从外部文件读取的,我的问题是这个文件有几行,在其中一些行中,我的参数值是空的,一些包含数据
我想自动删除自动测试中为空的参数,甚至删除key,直到不出现异常。
"length": "${DataSource#Length}",
"offset": "${DataSource#Offset}",
"cityCode": "${DataSource#CityCode}",
"cityName" : "${DataSource#CityName}" ,
"provinceCode": "${DataSource#ProvinceCode}",
"provinceName" : "${DataSource#ProvinceName}"
screenshot from soapui pro
您可以在 运行 和 API 之前写一个 groovy 步骤 ,您将在其中根据空值准备输入变量
逻辑:-
- 从数据源中提取值
- 检查它们是否为 null 不要将它们添加到输入中
- 因此最终准备好的字符串存储在测试用例中属性
- 属性可以在实际的休息请求中展开
`
String jsonInput=""
def Length=context.expand("${DataSource#Length}")
def offset=context.expand("${DataSource#Offset}")
if(Length)
{
jsonInput=jsonInput+Length
}
if(offset!=null)
{
jsonInput=jsonInput+offset
}
testRunner.testCase.setPropertyValue("jsonInput",jsonInput)
现在您可以在休息步骤中提及
${#TestCase#jsonInput}
如何将一个参数发送到 rest api,它可以为 null 或有一些值? 我想用 json 发送这个参数。 数据是从外部文件读取的,我的问题是这个文件有几行,在其中一些行中,我的参数值是空的,一些包含数据 我想自动删除自动测试中为空的参数,甚至删除key,直到不出现异常。
"length": "${DataSource#Length}",
"offset": "${DataSource#Offset}",
"cityCode": "${DataSource#CityCode}",
"cityName" : "${DataSource#CityName}" ,
"provinceCode": "${DataSource#ProvinceCode}",
"provinceName" : "${DataSource#ProvinceName}"
screenshot from soapui pro
您可以在 运行 和 API 之前写一个 groovy 步骤 ,您将在其中根据空值准备输入变量
逻辑:-
- 从数据源中提取值
- 检查它们是否为 null 不要将它们添加到输入中
- 因此最终准备好的字符串存储在测试用例中属性
- 属性可以在实际的休息请求中展开
`
String jsonInput=""
def Length=context.expand("${DataSource#Length}")
def offset=context.expand("${DataSource#Offset}")
if(Length)
{
jsonInput=jsonInput+Length
}
if(offset!=null)
{
jsonInput=jsonInput+offset
}
testRunner.testCase.setPropertyValue("jsonInput",jsonInput)
现在您可以在休息步骤中提及
${#TestCase#jsonInput}