如何使用 groovy 脚本创建 属性?

How to create a property using groovy script?

在自动化脚本中,我需要创建一个 属性 并动态存储值,以便存储的值在后续步骤中用于进一步处理,有人可以帮忙吗。

我在网上试过每篇文章都在片场说,并在 groovy 中得到 属性,但我需要使用 Groovy 脚本测试步骤创建一个 属性。

如果您使用的是 SoapUI,以下代码片段有助于在测试用例级别创建 属性。

//Set a test case level custom property, say COLOR
context.testCase.setPropertyValue('COLOR', 'black')

//The same can be read back using below
def color = context.expand('${#TestCase#COLOR}')
assert 'black' == color

我认为上面创建的 属性 应该用于测试用例的其他步骤,因为 属性 可能是为了重用而创建的。

凡是需要黑色的地方,就用${#TestCase#COLOR},这种表示法叫做Property Expansion