2016-03-03 98 views
0

我在編寫SoapUI中的groovy腳本時,在編寫下面提到的代碼時,出現類似「No such propety:GetSupplierByCityResult for class:Script1」的錯誤。Groovy腳本在SoapUI中發生錯誤

了SoapUI反應:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 

<soap:Body> 
    <GetSupplierByCityResponse xmlns="http://www.webservicex.net/"> 
    <GetSupplierByCityResult>false</GetSupplierByCityResult> 
    <SupplierDataLists> 
     <SupplierDatas/> 
     <TotalRecords>0</TotalRecords> 
    </SupplierDataLists> 
    </GetSupplierByCityResponse> 
</soap:Body> 
</soap:Envelope> 

Groovy代碼:

//Define Groovy Utils and holder for validating the XML reponse content 

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) 
def holder = groovyUtils.getXmlHolder(messageExchange.responseContent) 

    //Define the NameSpace 
    holder.namespaces["ns"] = "http://www.webservicex.net" 

    //Get the Value of the Node 'GetReservationRSResult' and assign to a  variable 
    def GetReservationResponse = holder.getNodeValue("//GetSupplierByCityResult") 

    //print the value of the GetReservationResponse 
    log.info "The GetReservationResponse " + GetReservationResponse 

    //Comparing the value to print 'Pass' or 'Fail' 
    if(GetSupplierByCityResult=="false") 
    { log.info "Pass" } 
    else 
    { log.info "fail"} 

請幫我解決這個問題。

回答

0

在行:

if(GetSupplierByCityResult=="false") 

你的變量稱爲GetReservationResponse,不是嗎?

看起來從行方式:

def GetReservationResponse = holder.getNodeValue("//GetSupplierByCityResult") 

變量也應該與小寫字符(這是作爲否則Groovy中可能會猜到你在談論一個類時,你拿出遵循一個好習慣開始與一個不好名稱的變量)

+0

謝謝tim_yates爲您的支持,現在它工作正常。 – Sai