2017-04-12 90 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