Created
October 19, 2015 12:11
-
-
Save rupzme/a5a1e7ab2f6adb2051bc to your computer and use it in GitHub Desktop.
Random SoapUI Groovy Script Examples involving properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
context.ratings_down=context.ratings_down+1 | |
log.info context.ratings_down | |
Context variables can then be used in requests etc without any prefix notation e.g. ${ratings_down} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment