How to pass result from groovy script to Request body Parameter and Request header ?
Hello Team ,
I am using below code into groovy script and want to pass the variable value into Request body field and Request header field
My groovy script is
def Date= new Date().format("yyyy-MM-dd HH.mm.ss.SSSSS Z");
log.info("Date" +Date);(I want to pass this in request body field)
def Timestamp = new Date().format("yyyy-MM-dd");
log.info("timestamp" +Timestamp); (I want to pass this into request header)
Result is
Wed Nov 17 20:53:26 GMT 2021: INFO: Date2021-11-17 20.53.26.00460 +0000
Wed Nov 17 20:53:26 GMT 2021: INFO: timestamp2021-11-17
I am trying set this into request body using get data
but when I add the "result" I see no value under that date field in request body!
Please help me how to do that.
Hello ,
I tried with below option
testRunner.testCase.testSteps['Properties'].setPropertyValue("Date", Date.toString());
testRunner.testCase.testSteps['Properties'].setPropertyValue("Timestamp", Timestamp.toString());
.
Then I tried some exploration on how to setproperty on test cases level and tried below solution
String timestamp=new Date().format("yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC"))
testRunner.testCase.setPropertyValue( "TimeStamp", timestamp )
log.info(timestamp);String date = new Date().format("yyyy-MM-dd")
testRunner.testCase.setPropertyValue( "Date", date )
log.info(date);I retrieve value from test case properties using "Get Data" and used in Request body and request Header Parameter and it worked!
Thank you for your reply. I got lead to search in right direction!
Thanks,
Neha