cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
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
Highlighted
Community Hero

Please use "${#TestCase#dateNow}"


Regards,
Rao.

View solution in original post

1 REPLY 1
Highlighted
Community Hero

Please use "${#TestCase#dateNow}"


Regards,
Rao.

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!