Ask a Question

working with parameters


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: 


it returns "+1" like the parameter was a string. 

I would expect "1".




Valued Contributor



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}')) 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:




(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 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 context.ratings_down  // prints 0
context.ratings_down=context.ratings_down+1 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?





Author of SoapUI Cookbook

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, 




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?




Author of SoapUI Cookbook
Showing results for 
Search instead for 
Did you mean: