我不确定如何使用属性转移步骤来实现这一点,因为它似乎是数据操作。
如果可以实现,我会以下面的方式(使用脚本断言)执行此操作。
只有两步
为获取详细信息步骤添加Script Assertion
以下代码:
import groovy.json.*
//Read the response of GetDetails and filter details
def details = new JsonSlurper().parseText(context.response).details
//assert there is details available and not empty
assert details, "Details is empty or null in the response"
//Creating object to build the next step request
def json = new JsonBuilder()
//Building details object for Change
json.details {
//looping thru each data
details.each { key, value ->
//Change state to inactive
if ('state' == key) value = 'non-active'
//add the properties inside details
"$key"("$value")
}
}
//Create a pretty print sting and this is going to be the next test step's request
def prettyJson = JsonOutput.prettyPrint(json.toString())
//Assign this data to a test step custom property, say REQUEST
context.testCase.setPropertyValue('REQUEST', prettyJson)
在 Change Details 步骤中,打开 request editor => have${#TestCase#REQUEST}
现在运行您的测试,看看它是否按您的需要工作。
注意:它在评论中提到inactive
,但在问题中提到non-active
- 所以在回复中保持不变。我认为在这种情况下这没什么大不了的,我相信。