Jmeter - JMS Publisher - 如何从 XML 请求中获取值
Jmeter - JMS Publisher - How to get the value from XML request
我正在尝试从我从 JMS 发布者发送到 JMS 订阅者的 xml 文档中获取一个值。
<?xml version="1.0" encoding="UTF-8"?>
<sys1>
<req>
<id>123</id>
<message>hello</message>
</req>
</sys1>
文档被转换。我需要检查 xml-document 中的“id”在转换后是否保持不变。
当我从订阅者那里得到“id”时 - 我只使用 Post 处理器 - XPath 提取器并得到它。
但是在 Publisher 中使用它时我什么也没得到。
我读了一些 jmeter 手册,发现“此测试元素(XPath 提取器)允许用户从结构化 response - XML 或(X)HTML - 使用 XPath 查询语言。"
然后我尝试使用正则表达式提取器获取它,但它也只适用于响应。
但是我怎样才能从请求中得到它呢?
我认为您只能使用 JSR223 PostProcessor 访问请求数据,示例代码如下:
def id = new groovy.xml.XmlParser().parseText(ctx.getCurrentSampler().getTextMessage()).req.id.text()
如果您想将结果存储到 JMeter Variable 中,您也可以添加下一行:
vars.put('id', id)
完成后,您将能够在需要时以 ${id}
的形式访问提取的值
上面代码中ctx
代表JMeterContext class instance, see the JavaDoc for description of all methods and fields and Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on this and other JMeter API shorthands available for the JSR223 Test Elements
您可能还对 Groovy 文档的 Apache Groovy - Processing XML 章感兴趣
我正在尝试从我从 JMS 发布者发送到 JMS 订阅者的 xml 文档中获取一个值。
<?xml version="1.0" encoding="UTF-8"?>
<sys1>
<req>
<id>123</id>
<message>hello</message>
</req>
</sys1>
文档被转换。我需要检查 xml-document 中的“id”在转换后是否保持不变。 当我从订阅者那里得到“id”时 - 我只使用 Post 处理器 - XPath 提取器并得到它。
但是在 Publisher 中使用它时我什么也没得到。
我读了一些 jmeter 手册,发现“此测试元素(XPath 提取器)允许用户从结构化 response - XML 或(X)HTML - 使用 XPath 查询语言。"
然后我尝试使用正则表达式提取器获取它,但它也只适用于响应。 但是我怎样才能从请求中得到它呢?
我认为您只能使用 JSR223 PostProcessor 访问请求数据,示例代码如下:
def id = new groovy.xml.XmlParser().parseText(ctx.getCurrentSampler().getTextMessage()).req.id.text()
如果您想将结果存储到 JMeter Variable 中,您也可以添加下一行:
vars.put('id', id)
完成后,您将能够在需要时以 ${id}
的形式访问提取的值
上面代码中ctx
代表JMeterContext class instance, see the JavaDoc for description of all methods and fields and Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on this and other JMeter API shorthands available for the JSR223 Test Elements
您可能还对 Groovy 文档的 Apache Groovy - Processing XML 章感兴趣