4
votes

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?
2

2 Answers

3
votes

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:

XPath Assertion configuration

2
votes

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.

JMeter Xpath Name

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: