问题
I had been stuck while playing with the SOAP UI getting started tutorial because i can't produce an assertion condition for a simple testing. I'm Using the XPATH method to test the following SOAP message:
<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>
I'm using the following Xpath expression:
declare namespace i='http://www.w3.org/2001/XMLSchema-instance';
//i:GetCityWeatherByZIPResult[1]/i:Success[1]
and this is the error:
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
回答1:
Using defined namespaces in SoapUI XPath assertions unnecessarily complicates things, and in some cases outright does not work. Start with just //*:GetCityWeatherByZIPResult/*:Success
for your XPath, and work up from there as needed.
来源:https://stackoverflow.com/questions/24831248/error-getting-a-node-on-soap-uis-test-case-xpath