我想访问请求参数,并使用groovy脚本将其与响应JSON中的特定节点进行匹配。
以下是我试过的代码
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(Request.requestContent)
def id = String.valueOf(holder.getNodeValue(“destination”))
但SOAP UI出现错误“变量名必须以字母开头,但找到”目的地“
我也试过
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def project = context.testCase.testSuite.project
def testSuite = project.getTestSuiteAt(0)
log.info(testSuite.getLabel())
def testCase = testSuite.getTestCaseAt(0)
log.info(testCase.getLabel())
def testStep = testCase.getTestStepAt(0)
log.info(testStep.getLabel())
def teststepname = testCase.getTestStepAt(0).getName().toString()
def inputHolder = teststepname + "#Request"
log.info(inputHolder);
def holderRawReq = groovyUtils.getXmlHolder(inputHolder)
def destination = holderRawReq.getNodeValue("destination")
log.info destination
但它显示错误“null后文件意外结束”
请帮忙。我很感激。
答案 0 :(得分:0)
我找到了解决方案。您可以访问请求参数并将其与SOAPUI Groovy脚本中的特定节点进行匹配。
import groovy.json.JsonSlurper
def request = context.testCase.getTestStepAt(0).getProperty("destination").getValue()
log.info request
//grab the response
def ResponseMessage = messageExchange.response.responseContent
//define a JsonSlurper
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
//verify the slurper isn't empty
assert !(jsonSlurper.isEmpty())
assert jsonSlurper.routes[0] != null
log.info jsonSlurper.routes[0].legs[0].end_address
def end_address = jsonSlurper.routes[0].legs[0].end_address
end_address.toString().contains("$request")