I've been trying to build a payload using nested Embedded Expressions. This is an example of the feature file:
Feature: missing part of the payload
Background:
* url 'http://localhost:9090'
* def localDateTime = Java.type('java.time.LocalDateTime')
#* def time = localDateTime.now().plusHours(2)
@ignore
@reuse=CreateDog
Scenario: Create Dog
* def payload =
"""
{
"name": '#(dogName)',
"age": '#(dogAge)',
"adoptionData": '##(adoptionData)'
}
"""
* print payload
When path 'createDog'
And request payload
And method Post
Scenario: Create Dog From Table
* def time = localDateTime.now().plusHours(2)
* def adoptionData =
"""
{
"tutor": "Any Name",
"adoptionDate": '#(time)'
}
"""
* table createDogPayload
| name | age | adoptionData |
| 'my dog' | 33 | adoptionData |
When def result = call read('this:embededExpressionMissing.feature@reuse=CreateDog') createDogPayload
I want the Adoption Data to be Not Mandatory and that is why it has the '##(adoptionData)' in the payload. The value for the adoptionDate is generated by the time variable defined previously.
When I run the test the payload is printed with the right values but the request is sent without the time in the adoption date. Please check the print bellow. Karate testing logs Maybe I am doing something wrong here. I tried a few combinations but none of them fill the date as I am expecting.