【发布时间】:2016-04-19 10:55:37
【问题描述】:
我尝试在 SoapUI 中使用脚本断言进行 json 响应,但出现错误
“Lexing 在第 1 行,第 1 列失败,在读取 '
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="http://localhost">
<soapenv:Header/>
<soapenv:Body>
<loc:GetRoomAttribute>
<loc:countryId>123</loc:countryId>
<loc:locationId>36</loc:locationId>
<loc:roomId>213</loc:roomId>
</loc:GetRoomAttribute>
</soapenv:Body>
</soapenv:Envelope>
回应:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRoomAttributeResponse xmlns="http://localhost">
<GetRoomAttributeResult>{"roomAttribute":{"EndPointType":"SR","GroupId":23,"RegionId":22,"Occupancy":6}}</GetRoomAttributeResult>
</GetRoomAttributeResponse>
</soap:Body>
</soap:Envelope>
脚本断言:
import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText response
assert json.roomAttribute.EndPointType == "SR"
如何使用带有JsonSlurper 类的脚本断言来断言'EndPointType','GroupId','RegionId','Occupancy'。
【问题讨论】:
-
这是 XML,而不是您传递给
parseText的 Json -
你能告诉我如何断言这一点。谢谢