JMeter-用户定义的计数器不会为循环递增 [英] JMeter - User defined counter not incrementing for a Loop

查看:204
本文介绍了JMeter-用户定义的计数器不会为循环递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JMeter还是很陌生,我试图使用循环控制器和JSR223后处理器来增加用户定义变量中预定义的计数器变量,但它似乎无法正常工作.我查看了JMeter循环上的各种示例和计数器示例以解决此问题,但配置元素Counter并未随循环的增加而增加. 有人可以让我知道我在做什么错吗?

I am quite new to JMeter and I was trying to increment a counter variable pre-defined in User Defined Variables using a Loop Controller and a JSR223 PostProcessor and it seems not working well. I looked at various examples on JMeter loop and counter examples to work this out but the config element Counter was also not incrementing with the loop. Could anybody please let me know what I am doing wrong?

这是用户定义的变量计数器:

这是我的循环方式:

这是我尝试使用后处理器递增计数器的方式,并且日志显示计数器未针对每个循环递增.我想将计数器提高到5:

我猜不清楚我为什么要使用$ {counter}进行测试.我试图将另一个变量内的计数器变量评估为'$ {__ V(transaction _ $ {counter})}',因为这需要附加到文本文件中.例如,如果transaction_3的值为"110001",如果我要附加'$ {__ V(transaction _'+ vars.get('counter')+')}',则存储的文本将显示为"transaction_3",如果执行'$ {__ V(transaction _ $ {counter})}',然后我得到存储在文本文件中的正确值"110001",而在下一次迭代中,计数器不递增.有没有可能解决这个问题的方法?

I guess I wasn't clear on why I used ${counter} to test out. I was trying to evaluate the counter variable within another variable as '${__V(transaction_${counter})}' because this needs to be appended to a text file. For example, if transaction_3 has a value "110001", if I do '${__V(transaction_'+vars.get('counter')+')}' to append, the text stored shows "transaction_3" and if I do '${__V(transaction_${counter})}' then I get the correct value "110001" stored in the text file while in next iteration the counter does not increment. Is there a possible way to solve this problem?

这是我在变量中使用变量的方式,它表明值没有改变因为计数器没有变化.

这张图片是我尝试使用vars.get()的方法,它显示了只是放置变量名而不是评估每个项目的值.

推荐答案

根据 JSR223采样器文档:

JMeter在将脚本字段传递给解释器之前先处理函数和变量引用,因此这些引用将仅被解析一次.脚本文件中的变量和函数引用将逐字传递给解释器,这可能会导致语法错误.为了使用运行时变量,请使用适当的props方法,例如

JMeter processes function and variable references before passing the script field to the interpreter, so the references will only be resolved once. Variable and function references in script files will be passed verbatim to the interpreter, which is likely to cause a syntax error. In order to use runtime variables, please use the appropriate props methods, e.g.

props.get("START.HMS");
props.put("PROP1","1234");

因此,将脚本的最后一行修改为:

So amend the last line of your script to look like:

log.info(vars.get('counter'))

演示:

另外请注意,它更容易使用:

Also be aware that it's much easier to use:

  1. Counter 测试元素或
  1. Counter test element or __counter() function, check out How to Use a Counter in a JMeter Test article for more details
  2. Loop Controller exposes ${__jm__Loop Controller__idx} JMeter Variable which holds current iteration number

这篇关于JMeter-用户定义的计数器不会为循环递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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