2017-02-20 18 views
1

下面是我的GetCountry請求的表格響應。如何使用SoapUI中的Property Transfer從表格響應中轉移屬性值?

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <soap:Body> 
     <GetCitiesByCountryResponse xmlns="http://www.webserviceX.NET"> 
     <GetCitiesByCountryResult><![CDATA[<NewDataSet> 
    <Table> 
    <Country>British Indian Ocean Territory</Country> 
    <City>Diego Garcia</City> 
    </Table> 
    <Table> 
    <Country>India</Country> 
    <City>Ahmadabad</City> 
    </Table> 
    <Table> 
</NewDataSet>]]></GetCitiesByCountryResult> 
     </GetCitiesByCountryResponse> 
    </soap:Body> 
</soap:Envelope> 

在這裏,我要的值複製瞭如:Country = IndiaCity = Ahmadabad我的目標要求。如何使用Property transfer方法傳輸這些值?有人可以幫助我的格式?

+0

是國家名稱,城市名稱值固定? – Rao

+0

是的,國家和城市的名稱是固定的 –

回答

2

我認爲這是不可能的財產轉讓步驟。 嘗試以下使用「腳本聲明」,這將解決您的問題:

定義與所需要的國家和城市名

  1. 屬性名稱在測試用例級別以下的自定義屬性 - CountryName和值India
  2. 物業名稱 - CityName和值Ahamadabad

添加腳本斷言。如何在SOAP UI中添加腳本斷言請參考Link

def searchData = { data, element -> 
    def parsedData = new XmlSlurper().parseText(data) 
    parsedData.'**'.find {it.name() == element} as String 
} 

//Closure to check the xpath 
def searchByXpath = {data, xpath -> 
    def holder = new com.eviware.soapui.support.XmlHolder(data) 
    holder.getNodeValue(xpath) 
} 
assert context.response, "Response is empty or null" 
//Gets the CDATA part of the response 
def cdata = searchData(context.response, 'GetCitiesByCountryResult') 

//Gets the xpath result 
def cityName = context.expand('${#TestCaes#CityName}') 
def countryName = context.expand('${#TestCaes#CountryName}') 
def result = searchByXpath(cdata, "exists(//Table[City = '$cityName' and Country = '$countryName'])") 
log.info "Is city ${cityName} and Country ${countryName} exist in the table: ${result}" 
assert result == 'true', "${cityName} and ${countryName} does not exist in the result table" 

立即訪問下一請求上述定義的屬性是提定義如下:(使用屬性擴展)

<web:CountryName>${#TestCase#CountryName}</web:CountryName> 
<web:CityName>${#TestCase#CityName}</web:CityName> 
+0

你有一個關於這是否可以使用Groovy Script完成的想法? –

+0

用請求的信息更新了答案。請穿過它並試一試。 –

相關問題