1

My payload looks like this :

{
  "override_source": "DS",
  "property_code": "0078099",
  "stay_date": "2018-11-26T00:00:00.000000",
  "sku_prices": [
  ],
  "persistent_override": false
}

There is an array dblist ["2","3"] , it would consists of numbers from 1 to 4. Based on the elements present in the list, I want to add key-values {"sku_price":"1500","sku_code":"2"} to my payload. I am using the following code :

* eval if(contains("3",dblist)) karate.set('pushRatesFromDS.sku_prices[]','{ "sku_price": "1500","sku_code":"3" }')

When I execute my feature file, I do not get any errors but, key-values are not added to my payload. However if I move this code to a new feature file and call it, key-value pairs get added to my payload. The code in my new feature file looks like : * set pushRatesFromDS.sku_prices[] = { "sku_price": "1500","sku_code":"2" }

0

1 Answer 1

2

Try this:

* def foo =
"""
{
  "override_source": "DS",
  "property_code": "0078099",
  "stay_date": "2018-11-26T00:00:00.000000",
  "sku_prices": [
  ],
  "persistent_override": false
}
"""
* eval karate.set('foo', '$.sku_prices[]', { foo: 'bar' })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.