Ask a Question

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

SOLVED
martinrampton
Occasional Contributor

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")
}

1 ACCEPTED SOLUTION

Accepted Solutions
jhanzeb1
Frequent Contributor

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

Hi,

 

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

 

I hope this helps

View solution in original post

2 REPLIES 2
jhanzeb1
Frequent Contributor

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

Hi,

 

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

 

I hope this helps

View solution in original post

martinrampton
Occasional Contributor

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

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"))
}

cancel
Showing results for 
Search instead for 
Did you mean: