如何在JMeter中使用正则表达式提取器提取某些值? [英] How to extract certain values using regular expression extractor in JMeter?

查看:1696
本文介绍了如何在JMeter中使用正则表达式提取器提取某些值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个相同的标签和相同的属性,唯一的区别是值,我该如何提取第二个?

In the case where I have two identical tags and identical attributes and the only difference is the value, how can I extract the second one?

<data xsi:type="soapenc:string">0</data>
<data xsi:type="soapenc:string">1</data>

我尝试执行以下操作.

<data xsi:type="soapenc:string">0</data><data xsi:type="soapenc:string">(.+?)</data>

并将值分配给myID.但是,当我在脚本中放入$ {myID}时,它使用的是字符串"$ {myID}"而不是实际值.是提取不起作用吗?还是我需要使用其他变量?

And assign the value to myID. But when I put in ${myID} in the script, it is using the string "${myID}" instead of the actual value. Is it that the extraction not working? Or do I need to use a different variable for it?

我有一个不同的采样器,其中只有一个标签.例如,

I have a different sampler where I have only one tag. For example,

<data xsi:type="soapenc:string">0</data>

当我这样做的时候,

<data xsi:type="soapenc:string">(.+?)</data>

并分配给myAnotherID,我可以使用$ {myAnotherID},该值将在脚本中使用.

and assign to myAnotherID, I can use ${myAnotherID} and the value would be used in the script.

那么,为什么$ {myID}不返回值?

So, why is it that ${myID} does not return the value?

预先感谢, 蒙特

推荐答案

使用单个表达式-<data xsi:type="soapenc:string">(.+?)</data>-获取所有匹配项.
如果存在多个匹配项,则jmeter将根据您要提取的变量名称为每个匹配项生成特定的变量-如refName_N:您的案例中的myAnotherID_1,myAnotherID_2,...,myAnotherID_N.
然后,您可以通过相应的变量(示例中的myAnotherID_1)引用所需的值.

Use the single expression - <data xsi:type="soapenc:string">(.+?)</data> - to get all the matches.
If there are more than one match jmeter will generate specific variables for each match, based on the variable name to which you are trying to extract - like refName_N: myAnotherID_1, myAnotherID_2, ..., myAnotherID_N in your case.
Then you can refer required value via corresponding variable (myAnotherID_1 in your example).

  • 查看正则表达式提取器参考以获取匹配号说明.
  • 查看此帖子有关使用正则表达式提取器提取和访问一批值
  • 您还可以将调试采样器JMeter Variables = true一起使用,以查看全部提取一批值时生成的变量.
  • 查看这篇文章,可在不使用ForEach Controller的情况下循环浏览多个RegExp Extractor输出值.
  • Look into Regular Expression Extractor reference for Match Number explanation.
  • Look into this post about extracting and accessing batch of values using Regular Expression Extractor.
  • You can also use Debug Sampler with JMeter Variables = true to see all the variables generated upon extracting batch of values.
  • Look into this post for looping through multiple RegExp Extractor output values without ForEach Controller.

希望这会有所帮助.

这篇关于如何在JMeter中使用正则表达式提取器提取某些值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆