我在玩 SOAP UI 入门教程时一直卡住了,因为我无法为简单测试生成断言条件。我正在使用 XPATH 方法测试以下 SOAP 消息:
<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>
<GetCityWeatherByZIPResponse xmlns="http://ws.cdyne.com/WeatherWS/">
<GetCityWeatherByZIPResult>
<Success>false</Success>
<ResponseText>City could not be found in our weather data. Please contact CDYNE for more Details.</ResponseText>
<State/>
<City/>
<WeatherStationCity/>
<WeatherID>-1</WeatherID>
<Description/>
<Temperature/>
<RelativeHumidity/>
<Wind/>
<Pressure/>
<Visibility/>
<WindChill/>
<Remarks/>
</GetCityWeatherByZIPResult>
</GetCityWeatherByZIPResponse>
</soap:Body>
</soap:Envelope>
我正在使用以下 Xpath 表达式:
declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]
这是错误:
XPathContains assertion failed for path [declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]] : Exception:Missing content for xpath [declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]] in Response
最佳答案
在 SoapUI XPath 断言中使用定义的命名空间不必要地使事情复杂化,并且在某些情况下完全不起作用。从 //*:GetCityWeatherByZIPResult/*:Success
开始,然后根据需要从那里开始。
关于xml - 在 SOAP UI 的测试用例 XPATH 上获取节点时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24831248/