我是SoapUI的新手,刚刚配置了一个非常简单的MockService.是否可以操纵响应,以便对特定请求动态构建响应元素?
场景1:
请求:
<record>
<identifier>ID1</identifier>
</record>
Run Code Online (Sandbox Code Playgroud)
响应:
<response>
<child1>child 1</child1>
</response>
Run Code Online (Sandbox Code Playgroud)
场景2:
请求:
<record>
<identifier>ID2</identifier>
</record>
Run Code Online (Sandbox Code Playgroud)
响应:
<response>
<child2>child 2</child2>
</response>
Run Code Online (Sandbox Code Playgroud)
这是一个简单的测试,我不需要它做任何超过上述.我目前正在做以下事情,产生我想要的结果,但由于我是全新的,我相信有更好的选择:
响应:
<response>
${dynElement}
</response>
Run Code Online (Sandbox Code Playgroud)
Groovy脚本:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(mockRequest.requestContent)
def reqRef = String.valueOf(holder.getNodeValue("//identifier"))
def child1Text = "<child1>child 1</child1>"
def child2Text = "<child2>child 2</child2>"
if (reqRef == "ID1") {
context.setProperty("dynElement", child1Text)
} else if (reqRef == "ID2") {
context.setProperty("dynElement", child2Text)
}
Run Code Online (Sandbox Code Playgroud) soapui ×1