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

查看:24
本文介绍了如何在 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> - 获取所有匹配项.
如果有多个匹配项,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).

  • 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天全站免登陆