参考上一个问题: How to access the attribute value of soap UI response XML
我需要这个脚本是动态的,能够在每个测试运行时发送一个不同的XML体来解析。 如何实现这一目标?
示例XML
</script>
<form onsubmit="submitAction();return false;" name="submitForm" method="post" action="auth_vbv_browser_authentication.xsl">
<input value="auth_vbv_browser_authentication.xsl" type="hidden" name="AA_CurrentPage"/>
<input value="false" type="hidden" name="TDS_DeviceAuthentication"/>
<input value="0" type="hidden" name="mobileCount"/>
<table width="390" height="400" cellspacing="0" cellpadding="1" bgcolor="#e8e8e8" align="center">
<tr>
<td valign="top">
<table width="100%" style="padding:20px;" height="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">
<tr>
<td valign="top" height="1">
<img width="140" src="../580655198662148898/auth_issuer_logo_vbv.gif" height="47" border="0" align="left"/>
<img width="89" src="../580655198662148898/auth_vbv_lg.gif" height="51" border="0" align="right"/>
</td>
</tr>
<tr>
<td height="20"/>
</tr>
<tr>
<td height="1" colspan="3" align="right">
<font size="-2">
<span style="display:none" name="links">
<a onclick="return openDialog(2,1)" id="langLink_sec" href="#">???</a>
<a style="display:none" id="lang_link_sec">???</a>
English
</span>
<noscript>
<a href="auth_vbv_browser_authentication.xsl?AA_CurrentPage=auth_vbv_browser_authentication.xsl&AA_Ignore_Pattern=true&AA_LANCODE=1&SSID=1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce&popup=false">???</a>
English
</noscript>
</font>
</td>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_Heading_en">Enter Your Authentication Data</font>
</td>
</tr>
<tr>
<td height="1"/>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_TxtMain_en">Please enter your</font>
<font class="auth_TxtMain_en">Verified by VISA Password</font>
<font class="auth_TxtMain_en">in the field(s) below to verify your identity for this purchase. This information is not disclosed to the merchant.</font>
</td>
</tr>
<tr>
&#13;
(部分时间很长):
我需要从中获取SSID的值(1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce)。
尝试:
def xml = context.response
def holder = new com.eviware.soapui.support.XmlHolder(xml)
//use the xpath to retrieve the desctiption.
def ParRes = holder.getNodeValues("//*:input/@value")
//logging the descriptions
def str = new StringBuilder();
ParRes.each{
if("$it" != "InitAuth" ){
str = "$it"
}
}
return str
答案 0 :(得分:0)
如果Script Assertion用于获得响应的同一请求步骤,则很容易处理动态响应并解析它。因此,可以避免额外的groovy脚本步骤。
所需的所有更改都是从
更改第1个语句def xml = """
static xml content
"""
到
def xml = context.response
在你的问题中指出的其他解决方案仍然是相同的。
答案 1 :(得分:0)
由于您没有提供完整的回复,因此我只使用了表单标记:
<form onsubmit="submitAction();return false;" name="submitForm" method="post" action="auth_vbv_browser_authentication.xsl">
<input value="auth_vbv_browser_authentication.xsl" type="hidden" name="AA_CurrentPage"/>
<input value="false" type="hidden" name="TDS_DeviceAuthentication"/>
<input value="0" type="hidden" name="mobileCount"/>
<table width="390" height="400" cellspacing="0" cellpadding="1" bgcolor="#e8e8e8" align="center">
<tr>
<td valign="top">
<table width="100%" style="padding:20px;" height="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#ffffff">
<tr>
<td valign="top" height="1">
<img width="140" src="../580655198662148898/auth_issuer_logo_vbv.gif" height="47" border="0" align="left"/>
<img width="89" src="../580655198662148898/auth_vbv_lg.gif" height="51" border="0" align="right"/>
</td>
</tr>
<tr>
<td height="20"/>
</tr>
<tr>
<td height="1" colspan="3" align="right">
<font size="-2">
<span style="display:none" name="links">
<a onclick="return openDialog(2,1)" id="langLink_sec" href="#">???</a>
<a style="display:none" id="lang_link_sec">???</a>
English
</span>
<noscript>
<a href="auth_vbv_browser_authentication.xsl?AA_CurrentPage=auth_vbv_browser_authentication.xsl&AA_Ignore_Pattern=true&AA_LANCODE=1&SSID=1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce&popup=false">???</a>
English
</noscript>
</font>
</td>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_Heading_en">Enter Your Authentication Data</font>
</td>
</tr>
<tr>
<td height="1"/>
</tr>
<tr>
<td valign="top" height="1">
<font class="auth_TxtMain_en">Please enter your</font>
<font class="auth_TxtMain_en">Verified by VISA Password</font>
<font class="auth_TxtMain_en">in the field(s) below to verify your identity for this purchase. This information is not disclosed to the merchant.</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
根据我的理解,你想要SSID的值,即 1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce
并且您想在下一步中转移它,那么为什么不使用物业转移步骤并提供 Xpath ,如下所示:
substring-before(substring-after(/ form [@onsubmit =&#34; submitAction(); return false;&#34;] / table [@width =&#34; 390&#34;] / tr / td [ @valign =&#34;顶部&#34;] /表[@width =&#34; 100%&#34;] / TR [3] / TD [@height =&#34; 1&#34;] /字体[@size =&#34 -2&#34;] /无脚本/ A [@href =&#34; auth_vbv_browser_authentication.xsl AA_CurrentPage = auth_vbv_browser_authentication.xsl&安培; AA_Ignore_Pattern =真安培; AA_LANCODE = 1&安培; SSID = 1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce&安培;弹出=假&#34;] / @ HREF&#34; SSID =&#34;),&#34;&安培;&#34)
此Xpath的结果: 1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce
我已经在我的SOAPUI上测试了它并且工作正常。希望这有助于
注意:我已经从表单标记复制了Xpath,请根据您的要求更改Xpath,您可以使用在线工具来计算Xpath或任何XML编辑器。< / p>
有关Xpath的更多信息:Check this out