XPath JMeter Assertion : Error “prefix must resolve to a namespace”

[亡魂溺海] 提交于 2019-12-22 08:38:33

问题


I am trying to use JMeter XPath Assertion on a tag value as below with XPath assertion command:

//m:CurrencyNameResul/text() = Pounds

Webservice Response:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <m:CurrencyNameResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
      <m:CurrencyNameResult>Pounds</m:CurrencyNameResult>
    </m:CurrencyNameResponse>
  </soap:Body>
</soap:Envelope>

I am getting error

prefix must resolve to a namespace

and after referring to JMeter manual below:

NAMESPACES As a work-round for namespace limitations of the Xalan XPath parser implementation on which JMeter is based, you can provide a Properties file which contains mappings for the namespace prefixes:
prefix1=Full Namespace 1
prefix2=Full Namespace 2
…
You reference this file in jmeter.properties file using the property:
xpath.namespace.config

I don't get it, so my questions are:

  • what should be the content of Properties file?
  • where to put its path?

回答1:


Here is how to proceed:

Create in jmeter/bin folder a file named namespaces.properties containing:

m=http://www.oorsprong.org/websamples.countryinfo

In user.properties set:

xpath.namespace.config=namespaces.properties

Finally fix your assertion to contain:

//m:CurrencyNameResult = 'Pounds'

And check "Use Namespaces"

To end up with:




回答2:


You can amend your XPath query to use name() function like:

(//*[name() = 'm:CurrencyNameResult'])/text()

and you will not have to mess up with amending properties, restarting JMeter, etc.

Moreover if you go for local-name() function instead you will not have to include the namespace prefix into your query:

(//*[local-name() = 'CurrencyNameResult'])/text()

More information:

  • XPath language specification
  • Using the XPath Extractor in JMeter
  • XPath Tutorial


来源:https://stackoverflow.com/questions/52264871/xpath-jmeter-assertion-error-prefix-must-resolve-to-a-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!