首页 > 解决方案 > SOAPUI 如何在属性转移目标中将值增加 1?

问题描述

有两个测试步骤并尝试从一个测试步骤获取属性值到另一个测试步骤并将其增加 1。转移不是问题,但如何将其增加 1?

标签: soapui

解决方案


如果上面的代码确实是一个 Groovy 测试步骤,那么问题就出在第 1 行。您的代码看起来需要来自名为“Property Transfer”的测试步骤的 IncrementValue 值,但您的文本显示您已将自定义属性添加到测试案例,名称 IncrementValue。

要从测试用例客户属性中“提取”一个值,您需要执行此操作...

def incrementValue = context.expand( '${#TestCase#IncrementValue}' );

或者

def incrementValue = testRunner.testCase.getPropertyValue("IncrementValue");

您得到的错误是因为您试图将整数写入字符串属性。将整数转换为字符串,它将起作用。

看例子...

def incrementValue = testRunner.testCase.getPropertyValue("IncrementValue");

incrementValue = incrementValue.toInteger() + 1;


if (incrementValue <= 10) {
    // Prop name AND value are strings...
    testRunner.testCase.setPropertyValue("IncrementValue", incrementValue.toString());
}

log.info(incrementValue);

推荐阅读