Search code examples
groovypropertiessoapuiassertions

How to add or subtract from a property value in SoapUI using Groovy


In SoapUI, I am grabbing a testcase property that displays the value as 47.79.

def test= messageExchange.modelItem.testStep.testCase.getPropertyValue('test')

I want to grab this variable value and create two new variables. One will add up to a pence so that the value would be 47.80, and another that will subtract a pence so that it's 47.78.

I am unsure how to implement this in groovy as they tend to append at the end or give me error. How is it written in groovy to do the above?

Below is my attempt:

def testUp= Double.Parse(test) + 0.01
def testDown= Double.Parse(test) - 0.01

Thanks


Solution

  • Assuming that there a test case level property, say, test is defined with value 47.79 as stated in the question.

    The mistake in your script is Double.Parse()

    Here is the script it can do what you are looking for:

    //Get property value and convert it as Double
    def testValue = context.expand('${#TestCase#test}') as Double
    
    //Add and subtract with new variables.
    def testUp = testValue + 0.01
    def testDown = testValue - 0.01
    
    //Check if the values are correct, of course, value may vary based on the data.
    assert 47.80 == testUp
    assert 47.78 == testDown