2017-02-20 19 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

用请求的信息更新了答案。请穿过它并试一试。 –

相关问题