Jmeter-使用变量:循环中从JDBC请求到另一个JDBC查询 [英] Jmeter - Using varible: from JDBC request into another JDBC query under loop
问题描述
出于测试目的,基于JDBC查询ID,我需要传递到位于ForEach Controller下的另一个查询.
For the purpose of my test, Based on the JDBC query id's i need to pass to another query, located under ForEach Controller.
- 结果从query1返回
url id
https://pay1.com/ 1
https://pay3.com/ 3
https://pay8.com/ 8
基于返回的ID,我需要传递到另一个查询:
Based on the ID returned, i need to pass to another query:
select *
FROM transaction
WHERE id = '${id_1}'
如果我尝试:${id_1}
或${id_3}
正常工作.
If i try like: ${id_1}
or ${id_3}
is working fine.
但是,如何在不对索引进行硬编码的情况下动态传递给下一个查询?
But, how can i pass dynamically to the next query, without hard coding the index?
推荐答案
ForEach Controller具有预定义的变量,该变量根据
ForEach Controller has pre-defined variable exposing the current iteration, as per documentation:
JMeter将循环索引公开为名为
__jm__<Name of your element>__idx
的变量.因此,例如,如果将循环控制器命名为FEC
,则可以通过${__jm__FEC__idx}
访问循环索引.索引从0开始
JMeter will expose the looping index as a variable named
__jm__<Name of your element>__idx
. So for example, if your Loop Controller is namedFEC
, then you can access the looping index through${__jm__FEC__idx}
. Index starts at 0
所以
- 给定您的ForEach控制器名称为
ForEach Controller
,您可以使用${__jm__ForEach Controller__idx}
来访问其当前循环.
- 给定的索引是从零开始的,而变量是从1开始的,您需要在当前索引中加1,这可以使用 __V()函数使用您的
id_
前缀 评估结果表达式
- given your ForEach Controller name is
ForEach Controller
you can access its current loop as${__jm__ForEach Controller__idx}
- given indices are zero-based and your variables are 1-based you need to add 1 to the current index which can be done using __intSum() function
- and finally you will need to use __V() function in order to evaluate the resulting expression using your
id_
prefix
将所有内容放在一起,您正在寻找的代码将类似于:
Putting everything together, the code you're looking for would be something like:
${__V(id_${__intSum(${__jm__ForEach Controller__idx},1,)},)}
演示:
更多信息:这是合并多个JMeter变量的方法
这篇关于Jmeter-使用变量:循环中从JDBC请求到另一个JDBC查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!