我们如何在Jemter中使用XPath访问多个变量?

时间:2019-02-04 13:30:00

标签: xpath jmeter-4.0

我正在使用JMeter编写脚本来执行一些任务,这些任务中我想使用XPath extractor作为值参数值来访问第二个请求中的第一个请求的响应。

例如

这是我对XML格式的第一个请求的答复:

<a>
  <b>
    <c>

       <my_details>
          <first_name>A</first_name>
          <middle_name>B</middle_name>
          <last_name>C</last_name>
       </my_details>

    </c>
  </b>
</a>

现在,我想在第二个请求的值中使用名字和姓氏。为此,我使用XPath提取器从响应中获取值,如下所示:

enter image description here

但是我得到了如下响应:

        JMeterVariables:
        **full_name=A
        full_name_1=A**
        ...
        ...
        __jm__Thread Group__idx=0
        __jmeter.USER_TOKEN__=Thread Group 1-1

所以,我的问题是,如何使用单个XPath提取器获得全名?

2 个答案:

答案 0 :(得分:0)

尝试使用XPath提取器分别提取“ first_name”和最后一个“ last_name”,然后使用Beanshell后处理器为全名创建Jmeter变量,例如

vars.put(“ full_name”,vars.get(“ FIRST NAME JMETER VARIABLE”)+“” + vars.get(“ LAST NAME JMETER VARIABLE”));;

答案 1 :(得分:0)

使用 concat()函数(https://www.w3.org/2005/xpath-functions/),我能够实现所需的结果。

我使用了 XPath2提取器,并将Xpath查询设置为:

  

concat(// my_details / first_name,“”,// my_details / last_name)

XPath2 Extractor

这将导致为输出变量分配值“ A C”: enter image description here

请注意,目前建议使用 XPath2提取器https://jmeter.apache.org/usermanual/component_reference.html#XPath_Extractor):

enter image description here