working with parameters
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
working with parameters
Hi, I am pretty new to SoapUI.
I have a parameter that I would like to add 1 to after a test step.
How would I accomplish this?
How to I do maniplate parameters in SoapUI?
e.g I would like to add 1 [upcount] to a parameter ${#ratings_down}.
if I use:
${#ratings_down}+1
it returns "+1" like the parameter was a string.
I would expect "1".
Thanks
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ratingsDown
testRunner.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 1
Context 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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much Rupert, It sure does help.
I tried out the 3rd option.
I got the parameter from testcase and converted it to an int:
def testCaseProperty = testRunner.testCase.getPropertyValue( "ratings_down" ) context.ratings_down = Integer.parseInt(testCaseProperty)
Then I could do calculations on it:
context.ratings_down = context.ratings_down + 1
and use it for assertions later.
Thanks again,
teak
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Teak,
Nice one - thanks for sharing the solution back so that others can see it.
If you're happy to, please can you also mark it as solved?
Cheers,
Rup
