我正在SoapUI中编写groovy脚本,同时编写下面提到的代码我得到的错误就像" No Such propety:GetSupplierByCityResult for class:Script1"。
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 :(得分:0)
在行中:
if(GetSupplierByCityResult=="false")
您的变量被称为GetReservationResponse
不是吗?
从这一行看:
def GetReservationResponse = holder.getNodeValue("//GetSupplierByCityResult")
变量也应该以小写字符开头(这是一个很好的约定,否则当你提出一个命名不佳的变量时,Groovy可能会猜到你正在谈论一个类)