3

Jmeter 如何在变量名中使用变量

 2 years ago
source link: https://www.lfhacks.com/tech/jmeter-nested-variable-references
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Jmeter 如何在变量名中使用变量

113.jpg

在Jmeter的变量名中使用变量(叫做嵌套变量名),这在循环中尤其有用,本文讨论这种实践。

使用 Jmeter __V 函数 可以做到这点。

比如我们有如下几个变量,变量名如下:

QUERY_0
QUERY_1
QUERY_2
QUERY_3
QUERY_4

同时我们有变量 index,那么可以组合为

${__V(QUERY_${index})}

就可以用 index 的值指定上述5个 QUERY 变量中的其中一个。比如,当 index=3 时,

${__V(QUERY_${index})} == ${QUERY_3}

循环体变量

Jmeter 的 循环控制器(Loop Controller) 中,有 内置计数器用于记录循环体运行的次数:

JMeter will expose the looping index as a variable named __jm__Name of your element__idx. So for example, if your Loop Controller is named LC, then you can access the looping index through ${__jm__LC__idx}. Index starts at 0*

内置计数器变量的名字是 __jm__循环控制器的名称__idx ,如果你循环控制器取名为 LC, 那么变量名就是 ${__jm__LC__idx} ,注意计数器从0开始。

为了在循环中依次取得上面5个变量值,可以用如下的写法:

${__V(QUERY_${__jm__LC__idx})}

这样就可以在循环中批量读取变量值


坚持原创不易。如果您觉得有收获,请考虑资助本站,以期待更多原创文章。

打赏作者,支持小站

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK