以下是我的GetCountry请求的表格响应。
<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 = India
和City = Ahmadabad
的值复制到我的目标请求中。如何使用Property transfer方法传输这些值?有人可以帮我格式化吗?
答案 0 :(得分:2)
我认为财产转移步骤是不可能的。 尝试使用下面的&#34;脚本断言&#34;这将解决您的问题:
在测试用例级别使用所需的国家/地区和城市名称定义以下自定义属性
CountryName
,值为India
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"
现在要在下一个请求中访问上面定义的属性,如下面所定义(使用Property expansion)
<web:CountryName>${#TestCase#CountryName}</web:CountryName>
<web:CityName>${#TestCase#CityName}</web:CityName>