如果对于不同的条件判断,希望得到的 response有些节点不同,则可以用这种soap ui groovy脚本编写方式进行
script编写的示例:
--------------------------log.info的日志输出,是在 soapUI的安装路D: oolsSoapUI-5.2.1in 径下面的 文件 global-groovy.log 中有对应的记录
------得到mock的请求的 xml内容
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
log.info("*********jiaoltjiaolt11111**********************************************************")
def code=holder.getNodeValue("//arg1")
log.info("code的值是:"+code)
def remark2=holder.getNodeValue("//remark2")
log.info("remark2的值是:"+remark2)
def internalCode=holder.getNodeValue("//internalCode")
log.info("internalCode的值是:"+internalCode)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
log.info("*********jiaoltjiaolt11111**********************************************************")
def code=holder.getNodeValue("//arg1")
log.info("code的值是:"+code)
def remark2=holder.getNodeValue("//remark2")
log.info("remark2的值是:"+remark2)
def internalCode=holder.getNodeValue("//internalCode")
log.info("internalCode的值是:"+internalCode)
------得到mock的返回的 xml内容
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockResponse.responseContent)
log.info("*********jiaoltjiaolt11111**********************************************************")
def agentCateName=holder.getNodeValue("//agentCateName")
log.info("agentCateName的值是:"+agentCateName)
def agentId=holder.getNodeValue("//agentId")
log.info("agentId的值是:"+agentId)
def internalCode=holder.getNodeValue("//internalCode")
log.info("internalCode的值是:"+internalCode)
log.info("**************testtest2222*****************************************************")
def holder = groovyUtils.getXmlHolder(mockResponse.responseContent)
log.info("*********jiaoltjiaolt11111**********************************************************")
def agentCateName=holder.getNodeValue("//agentCateName")
log.info("agentCateName的值是:"+agentCateName)
def agentId=holder.getNodeValue("//agentId")
log.info("agentId的值是:"+agentId)
def internalCode=holder.getNodeValue("//internalCode")
log.info("internalCode的值是:"+internalCode)
log.info("**************testtest2222*****************************************************")
------------------------编写条件判断-------------------
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def code=holder.getNodeValue("//arg1")
log.info("code的值是:"+code)
log.info("整个得到的mock请求的报文是:"+ mockRequest.requestContent)
def successed="true"
if (code=="2928681")
successed="true"
else
successed="false"
context.setProperty("successed",successed)
log.info("**************testtest2222*****************************************************")
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def code=holder.getNodeValue("//arg1")
log.info("code的值是:"+code)
log.info("整个得到的mock请求的报文是:"+ mockRequest.requestContent)
def successed="true"
if (code=="2928681")
successed="true"
else
successed="false"
context.setProperty("successed",successed)
log.info("**************testtest2222*****************************************************")
对应的response的报文如下: