Forum Discussion

nd's avatar
New Contributor
3 years ago

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("yy...
  • nd's avatar
    3 years ago

    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 );


    String date = new Date().format("yyyy-MM-dd")
    testRunner.testCase.setPropertyValue( "Date", 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!