2017-04-12 89 views
0

参照此之前的问题: How to access the attribute value of soap UI response XML如何XML效应初探发送到Groovy脚本中了SoapUI

我需要这个脚本是动态的,能够每次测试运行发送一个不同的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&amp;AA_Ignore_Pattern=true&amp;AA_LANCODE=1&amp;SSID=1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce&amp;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>

(它很长的部分):

我需要从这个走出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 
+1

你提出的是不是一个XML。 – Rao

+0

我把它作为HTML,但我需要从XML响应视图中检索参数,这是唯一可以看到它的地方。 –

+0

也许有一种方法可以将此属性作为responseAsXml进行传输?但我将如何指定我需要的? –

回答

0

这是很容易处理的动态响应,并对其进行分析,如果是用于同一请求步骤,你得到的回应。因此可以避免额外的groovy脚本步骤。

所有更改需要的是从

def xml = """ 
static xml content 
""" 

改变1日声明,

def xml = context.response 

,溶液的其余部分在你的问题指出保持不变。

+0

我得到:org.apache.xmlbeans.XmlException:错误:不关闭标记。 –

+0

还有一件事,目的不是断言。我需要从xml传递一些值到另一个测试步骤。 –

+0

'code'def xml = context.response def holder = new com.eviware.soapui.support.XmlHolder(xml) def ParRes = holder.getNodeValues(“// *:input/@ value”) –

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&amp;AA_Ignore_Pattern=true&amp;AA_LANCODE=1&amp;SSID=1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce&amp;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(subst ring-after(/ form [@ onsubmit =“submitAction(); return false;”]/table [@ width =“390”]/tr/td [@ valign =“top”]/table [@ width =“100 %]]/tr [3]/td [@ height =“1”]/font [@size =“ - 2”]/noscript/a [@ href =“auth_vbv_browser_authentication.xsl?AA_CurrentPage = auth_vbv_browser_authentication.xsl & AA_Ignore_Pattern =真正& AA_LANCODE = 1 & SSID = 1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce &弹出=假 “]/@ HREF,” SSID = “),” &“)这个XPath的

结果:1710d5e8428fd9d53db2fe7cfb1c79a5af0ecce

我已经测试过它在我的SOAPUI和正常工作。希望这可以帮助

注:我从标签复制Xpath的,请更改Xpath的按照您的要求,您可以使用在线工具来calulate XPath或任何XML编辑器。

欲了解更多关于Xpath的信息:Check this out