Jmeter-使用变量:循环中从JDBC请求到另一个JDBC查询 [英] Jmeter - Using varible: from JDBC request into another JDBC query under loop

查看:81
本文介绍了Jmeter-使用变量:循环中从JDBC请求到另一个JDBC查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,基于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.

  1. 结果从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 named FEC, then you can access the looping index through ${__jm__FEC__idx}. Index starts at 0

所以

  • 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屋!

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