如何使用 Groovy 在 SoapUI 中添加或减去 属性 值

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

在 SoapUI 中,我正在抓取一个显示值为 47.79 的测试用例 属性。

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

我想获取这个变量值并创建两个新变量。一个将加起来为 1 便士,因此该值为 47.80,另一个将减去 1 便士,因此为 47.78。

我不确定如何在 groovy 中实现它,因为它们倾向于在末尾附加或给我错误。 groovy里面是怎么写的呢?

以下是我的尝试:

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

谢谢

假设有一个测试用例级别 属性,例如,test 定义为问题中所述的值 47.79

你脚本中的错误是Double.Parse()

这是脚本,它可以满足您的需求:

//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

正确的函数名称是:Double.parseDouble(test)

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

    def testUp= Double.parseDouble(test) + 0.01


    log.info testUp
    log.info testUp.getClass()