Forum Discussion

nd's avatar
nd
New Contributor
4 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
    nd
    4 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 )
    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