working with parameters
- 10 years ago
Hi,
Project, TestSuite & TestCase properties are actually of type String, but you can still increment them in a variety of ways e.g. by parsing the property value into a int type in a Groovy TestStep:
def ratingsDown = Integer.parseInt(context.expand('${#TestCase#ratings_down}'))
log.info ratingsDown+1(if ratings_down was 2, this would log 3 - note without the Integer.parseInt(...), this would output 21)
(assumes the propety ratings_down is against a TestCase object, hence the #TestCase# before the property)
To add on insert into a request:
${=${#TestCase#ratings_down}+1}
(if ratings_down was 2, this would insert 3)
Note this wouldn't increment the actual property value, you could do this in a Groovy TestStep e.g.
def ratingsDown = Integer.parseInt(context.expand('${#TestCase#ratings_down}'))
ratingsDown = ratingsDown+1
log.info ratingsDowntestRunner.testCase.setPropertyValue("ratings_down", String.valueOf(ratingsDown))
Running this would increment the value of property ratings_down againsts the TestCase.
Yet another option, which may be better is to set a property against the TestCase context map, these can be objects e.g. in a Groovy script you could do something like:
context.ratings_down=0
log.info context.ratings_down // prints 0
context.ratings_down=context.ratings_down+1
log.info context.ratings_down // prints 1Context variables can then be used in requests etc without any prefix notation e.g. ${ratings_down}
There are many ways, does this help?
Cheers,
Rupert