1

How i can send one parameter in to rest api which can be null or have some value? i want send this parameter with json. Data is read from an external file,my problem is that this file has several rows and in some of these rows my parameter's value are empty and some containing data I want to automatically delete the parameters that are empty in the automatic test and even remove the key until the exception does not occur.

"length": "${DataSource#Length}",
"offset": "${DataSource#Offset}",
"cityCode": "${DataSource#CityCode}",
"cityName" : "${DataSource#CityName}" ,
"provinceCode": "${DataSource#ProvinceCode}",
"provinceName" : "${DataSource#ProvinceName}"

screenshot from soapui pro

Melika
  • 27
  • 6
  • check this answer https://stackoverflow.com/questions/19557184/how-to-pass-json-data-to-restful-web-services-through-ajax-and-also-how-to-get-j – Vindhyachal Kumar Jul 17 '18 at 05:50

1 Answers1

0

You can write a groovy step before running the API, where you will prepare your input based on null value in a variable

Logic :-

  1. Extract the values from datasource
  2. check if they are null don't add them in the input
  3. So the final string prepared is stored in a testcase property
  4. that property can be expanded in the actual rest request

`

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)

Now in the Rest step you can mention

  ${#TestCase#jsonInput}
Gaurav Khurana
  • 3,423
  • 2
  • 29
  • 38