Search code examples
xpathjmeterperformance-testingxml-namespaces

XPath JMeter Assertion : Error "prefix must resolve to a namespace"


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?

Solution

  • 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