Forum Discussion

martinrampton's avatar
martinrampton
Occasional Contributor
6 years ago
Solved

How to I set the value of a test case property from a groovy script

I have a working groovy script that adds 1 day onto a date stored in a property called 'quoteexpirydate'... the script works fine and I can see the result in the log.info window. My question is, how do I set the value of another property 'quoteexpirydate_plus' so I can use this in my next REST request message. Here is my existing Groovy script:

 

use(groovy.time.TimeCategory) {
def quoteexpirydate = context.expand ( '${#TestCase#quoteexpirydate}' )
def formated_quoteexpirydate = Date.parse("yyyy-MM-dd", quoteexpirydate)
def onedayfromexpirydate = formated_quoteexpirydate + 1.day
log.info onedayfromexpirydate.format("yyyy-MM-dd")
}

  • Hi,

     

    testRunner.testCase.getTestStepByName.setPropertyValue("quoteexpirydate_plus", yourVariableForThis)

     

    I hope this helps

2 Replies

  • jhanzeb1's avatar
    jhanzeb1
    Frequent Contributor

    Hi,

     

    testRunner.testCase.getTestStepByName.setPropertyValue("quoteexpirydate_plus", yourVariableForThis)

     

    I hope this helps

    • martinrampton's avatar
      martinrampton
      Occasional Contributor

      Thanks, eventual working code looks like this:

       

      use(groovy.time.TimeCategory) {
      def quoteexpirydate = context.expand ( '${#TestCase#quoteexpirydate}' )
      def formated_quoteexpirydate = Date.parse("yyyy-MM-dd", quoteexpirydate)
      def onedayfromexpirydate = formated_quoteexpirydate + 1.day
      def testCaseProperty = testRunner.testCase.setPropertyValue("quoteexpirydate_plus", onedayfromexpirydate.format("yyyy-MM-dd"))
      }