我们可以像使用SoapUI工具中的soap服务一样,使用setNodeValue方法设置其余服务的节点值吗?

问题描述 投票:0回答:1

我们可以像在SoapUI工具中对肥皂服务那样使用setNodeValue方法来设置其余服务的节点值吗?

ex-

XMLHolder。setNodeValue(“ // typ:name”,名称)

XMLHolder。setNodeValue(“” // typ:id“,id)

XMLHolder。setNodeValue(“” // typ:部门“,部门)

XMLHolder。setNodeValue(“” // typ:age“,年龄)

rest groovy soapui web-api-testing
1个回答
0
投票

REST可以容纳XML以及JSON,您需要哪一个?如果您使用XML,则可以使用相同的方法,如果将其用于JSON,请遵循以下内容

import groovy.json.JsonSlurper
import groovy.json.JsonOutput

// Define Request
def request = '{ "name":"John", "country":"India", "car":"Honda" }'

// Parse The Request
def jsonReq = new JsonSlurper().parseText(request);

// Set Values
jsonReq.name = "Wilfred"
jsonReq.country = "India"
jsonReq.car = "Honda"

// Parse JSON to string
def jsonReqAsString = JsonOutput.toJson(jsonReq)

// Print or You can do anything
log.info (jsonReqAsString)
© www.soinside.com 2019 - 2024. All rights reserved.