xpath 和 soapui,传输 属性。从 Get 嵌套 JSON 到测试套件中的 Post
xpath and soapui, Transfer Property. Getting nested JSON from a Get to a Post in a Test Suite
我正在尝试学习 SoapUI,但我没有找到任何关于如何执行从 Rest GET 请求到 Rest POST 请求的传输 属性 的好的指南。
我从 REST GET 请求返回了以下负载
{
"a":"a",
"b": { "b1":"b1", "b2":"b2" },
"c":"c"
}
我想拿走这个 JSON 并删除 c,然后将其余部分提交给 POST 请求。我希望post
{
"a":"a",
"b": { "b1":"b1", "b2":"b2" },
}
我正尝试在 SoapUI 中完成所有这些,但没有成功。我可以通过在源中说 属性 是 RseponseAsXML 而目标 属性 是 Request 来获取单个值。然后我使用命令//*:a
。但它只有returns那个值。
虽然我不希望这是 xml,但我严格按照 JSON 工作。
谢谢。
如果您想操纵 JSON 响应以在其他 TestStep
中使用,使用 groovy TestStep
比 Transfer testStep
更容易。因此,创建一个 groovy TestStep
并使用以下代码操作响应:
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
// get the response using the name of your test step
def response = context.expand('${REST Test Request#Response}')
// parse response
def jsonResp = new JsonSlurper().parseText(response)
// remove "c" element
jsonResp.remove("c")
// parse json to string in order to save it as a property
def jsonAsString = JsonOutput.toJson(jsonResp)
log.info jsonAsString // prints --> {"b":{"b1":"b1","b2":"b2"},"a":"a"}
// save the json response without "c" in a testCase property
testRunner.testCase.setPropertyValue('json_post',jsonAsString)
使用上面的代码解析响应,删除 c
元素并在 testCase
中另存为 属性 然后在您的 REST POST 中您可以使用按照代码获取新的 JSON:
${#TestCase#json_post}
希望这对您有所帮助,
我正在尝试学习 SoapUI,但我没有找到任何关于如何执行从 Rest GET 请求到 Rest POST 请求的传输 属性 的好的指南。
我从 REST GET 请求返回了以下负载
{
"a":"a",
"b": { "b1":"b1", "b2":"b2" },
"c":"c"
}
我想拿走这个 JSON 并删除 c,然后将其余部分提交给 POST 请求。我希望post
{
"a":"a",
"b": { "b1":"b1", "b2":"b2" },
}
我正尝试在 SoapUI 中完成所有这些,但没有成功。我可以通过在源中说 属性 是 RseponseAsXML 而目标 属性 是 Request 来获取单个值。然后我使用命令//*:a
。但它只有returns那个值。
虽然我不希望这是 xml,但我严格按照 JSON 工作。 谢谢。
如果您想操纵 JSON 响应以在其他 TestStep
中使用,使用 groovy TestStep
比 Transfer testStep
更容易。因此,创建一个 groovy TestStep
并使用以下代码操作响应:
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
// get the response using the name of your test step
def response = context.expand('${REST Test Request#Response}')
// parse response
def jsonResp = new JsonSlurper().parseText(response)
// remove "c" element
jsonResp.remove("c")
// parse json to string in order to save it as a property
def jsonAsString = JsonOutput.toJson(jsonResp)
log.info jsonAsString // prints --> {"b":{"b1":"b1","b2":"b2"},"a":"a"}
// save the json response without "c" in a testCase property
testRunner.testCase.setPropertyValue('json_post',jsonAsString)
使用上面的代码解析响应,删除 c
元素并在 testCase
中另存为 属性 然后在您的 REST POST 中您可以使用按照代码获取新的 JSON:
${#TestCase#json_post}
希望这对您有所帮助,