Ask a Question

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

SOLVED
luciekrist
New Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

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

Please use "${#TestCase#dateNow}"


Regards,
Rao.

View solution in original post

1 REPLY 1
nmrao
Community Hero

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

Please use "${#TestCase#dateNow}"


Regards,
Rao.

View solution in original post

cancel
Showing results for 
Search instead for 
Did you mean: