Forum Discussion

teak's avatar
teak
Contributor
10 years ago

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 ...
  • rupert_anderson's avatar
    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 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