Forum Discussion

luciekrist's avatar
luciekrist
New Contributor
6 years ago

Problem with accessing a property defined in groovy script (date now)

Hey guys I manage to generate today's date using this code:

 

def dateFormat = "yyyy-MM-dd"
def date = "${new Date().format(dateFormat) }"
testRunner.testCase.setPropertyValue('dateNow', date)

log.info date

 

it works well, the date is printed in the console. I have property (MyProperties step) on the same level as the groovy script (in test case) called dateNow. then I implement it into json body request like this: 

 

"date": "${MyProperties#dateNow}",

 

what happens is when I try to run the post request, insted of the right response i get this: {"error": "Bookings[0] date can't be blank"}

 

I tried everything, putting the date into string, instead of testRunner putting context etc but it does not seem to work. Do you have any idea what could be happenning and how to fix this?Thank you

  • nmrao's avatar
    nmrao
    Champion Level 3
    Please use "${#TestCase#dateNow}"