Groovy 在SOAPUI Rest测试中添加和断言随机值
我一直在尝试各种方法来发送一个随机值作为RESTTestCase负载的一部分。我还需要在返回的响应中断言该随机值 我能够向有效载荷添加一个随机值。但我无法在响应中断言该随机值 我试过以下方法Groovy 在SOAPUI Rest测试中添加和断言随机值,groovy,soapui,load-testing,Groovy,Soapui,Load Testing,我一直在尝试各种方法来发送一个随机值作为RESTTestCase负载的一部分。我还需要在返回的响应中断言该随机值 我能够向有效载荷添加一个随机值。但我无法在响应中断言该随机值 我试过以下方法 添加groovy脚本并设置全局变量 def randomValue=java.util.UUID.randomUUID() com.eviware.soapui.soapui.globalProperties.setPropertyValue(“randomValue”,randomValue) 然后将其作
非常感谢您提供的任何帮助。您走上了正确的道路 从测试设置脚本中设置随机值,如:
def randomValue // = whatever you like: UUID.randomUUID() or Math.random() work fine
testCase.setPropertyValue( "randomValue", randomValue.toString() )
这将为每个测试运行生成一个随机值。然后,在测试的任何地方,您都可以通过属性扩展将其称为
${{TestCase#randomValue}
您可能需要解析和构建请求
step.testRequest.setRequestContent(json)
JsonSlurper
或xmlSlurper
解析请求 def builder = new JsonBuilder(your_changed_json)
def json = builder.toPrettyString()
json = groovy.json.StringEscapeUtils.unescapeJava(json)
step.testRequest.setRequestContent(json)