XPath JMeter 断言:错误 "prefix must resolve to a namespace"

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

我正尝试在标签值上使用 JMeter XPath Assertion,如下所示,使用 XPath 断言命令:

//m:CurrencyNameResul/text() = Pounds

网络服务响应:

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

我遇到错误

prefix must resolve to a namespace

参考下面的 JMeter 手册后:

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

我不明白,所以我的问题是:

以下是如何进行:

在 jmeter/bin 文件夹中创建一个名为 namespaces.properties 的文件,其中包含:

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

在user.properties中设置:

xpath.namespace.config=namespaces.properties

最终修正您的断言以包含:

//m:CurrencyNameResult = 'Pounds'

并勾选"Use Namespaces"

最后:

您可以修改您的 XPath 查询以使用 name() 函数,例如:

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

而且您将不必搞乱修改属性、重新启动 JMeter 等。

此外,如果您改用 local-name() 函数,则不必在查询中包含命名空间前缀:

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

更多信息: