使用Soapui处理Soap响应..
这会将个别问题拉到对话框中..效果很好..
def ui = com.eviware.soapui.support.UISupport;
groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
holder = groovyUtils.getXmlHolder("Question#Response");
holder.namespaces["ns1"] = "http://some.namespace.com";
def responseId = holder.getNodeValue("//ns1:questionText");
ui.showInfoMessage( responseId,"Question being asked" );
进入下拉模型,事情变得有趣。 这有效,但只显示第一个问答作为下拉列表中的一个项目,并显示每次点击的下拉列表..我想显示问题标题和选项,换句话说,从前一个响应中读取xml响应来自SOAP ..
def ui = com.eviware.soapui.support.UISupport;
groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
holder = groovyUtils.getXmlHolder("Question#Response");
holder.namespaces["ns2"] = "http://some.namespace.com";
for (responseId in holder["//ns2:text"])
//ui.showInfoMessage( responseId,"Question being asked" );
ui.prompt("Question being asked", "text", [responseId])
//result = com.eviware.soapui.support.UISupport.prompt("Question being asked", "Question", [responseId])
以下是示例SOAP - 注意:我已删除了head / tail,因为我主要关注的是提取问题和响应ID。
<ns1:callStatus>
<ns1:statusCode>SUCCESS</ns1:statusCode>
<ns1:statusDescription>Questions and answers retrieved successfully</ns1:statusDescription>
</ns1:callStatus>
<ns1:payload xsi:type="ns2:Response" xmlns:ns2="http://some.namespace.com">
<ns2:questions>
<ns2:questionId>AAA</ns2:questionId>
<ns2:text>What is the color of your car?</ns2:text>
<ns2:choices>
<ns2:choiceId>111</ns2:choiceId>
<ns2:text>Blue</ns2:text>
</ns2:choices>
<ns2:choices>
<ns2:choiceId>222</ns2:choiceId>
<ns2:text>Green</ns2:text>
</ns2:choices>
<ns2:choices>
<ns2:choiceId>333</ns2:choiceId>
<ns2:text>Black</ns2:text>
</ns2:choices>
</ns2:questions>
<ns2:questions>
<ns2:questionId>BBB</ns2:questionId>
<ns2:text>What is the name of your dog?</ns2:text>
<ns2:choices>
<ns2:choiceId>111</ns2:choiceId>
<ns2:text>Barney</ns2:text>
</ns2:choices>
<ns2:choices>
<ns2:choiceId>222</ns2:choiceId>
<ns2:text>Rover</ns2:text>
</ns2:choices>
<ns2:choices>
<ns2:choiceId>333</ns2:choiceId>
<ns2:text>Patches</ns2:text>
</ns2:choices>
</ns2:questions>
<ns2:questions>
<ns2:questionId>CCC</ns2:questionId>
<ns2:text>What if the name of your spouse?</ns2:text>
<ns2:choices>
<ns2:choiceId>111</ns2:choiceId>
<ns2:text>Latecia</ns2:text>
</ns2:choices>
<ns2:choices>
<ns2:choiceId>222</ns2:choiceId>
<ns2:text>Mary</ns2:text>
</ns2:choices>
<ns2:choices>
<ns2:choiceId>333</ns2:choiceId>
<ns2:text>Samantha</ns2:text>
</ns2:choices>
</ns2:questions>
</ns1:payload>
答案 0 :(得分:1)
我遇到了同样的问题并构建了这个解决方法:
def ui = com.eviware.soapui.support.UISupport;
List<String> choice = new ArrayList<String>();
List<String> values = new ArrayList<String>();
/* Parse the XML to fill the lists in the following format.
Something like:
for (responseId in holder["//ns2:text"])
{
choice.add('${responseId.text} (${responseId.choiceId})')
values.add( responseId.choiceId )
}
*/
choice.add('label (value)')
values.add('value')
/* Note: The 'value' in the choice list is optional but
should be used if you have duplicate labels. */
// Some example data:
choice.add('Red (#FF0000)')
values.add('#FF0000')
choice.add('Green (#00FF00)')
values.add('#FF0000')
choice.add('Blue (#0000FF)')
values.add('#FF0000')
// Ask the question
def result = ui.prompt("Question being asked", "text", choice, 'val')
// The answer
log.info result
// The position of the answer
log.info choice.indexOf(result)
// The associated value
log.info values.get( choice.indexOf(result) )
希望这有助于某人。