XPath JMeter断言:错误“前缀必须解析为命名空间”

问题描述 投票:4回答:2

我试图使用XPath断言命令在标签值上使用JMeter XPath Assertion

//m:CurrencyNameResul/text() = Pounds

Web服务响应:

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

我收到了错误

前缀必须解析为命名空间

并在参考下面的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

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

  • 什么应该是属性文件的内容?
  • 它的路径在哪里?
xpath jmeter performance-testing xml-namespaces
2个回答
3
投票

以下是如何进行:

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

米= HTTP://www.oorsprong.org/websamples.countryinfo

在user.properties中设置:

xpath.namespace.config = namespaces.properties

最后修复你的断言包含:

// m:CurrencyNameResult ='磅'

并选中“使用命名空间”

最终得到:

XPath Assertion configuration


2
投票

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

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

你不必搞乱修改属性,重启JMeter等等。

JMeter Xpath Name

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

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

更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.