Jmeter-循环计数器在while循环中,不会在退出时重置 [英] Jmeter - Loop counter in while loop not resetting on exit

查看:751
本文介绍了Jmeter-循环计数器在while循环中,不会在退出时重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jmeter中具有以下代码构造:

I have the following code construct in Jmeter:

Test Plan
- CSV Data config (reading in test reacords)
- Execution Thread
- - Do While (contains condition Counter < 5)
- - - Counter element (set to start at 1, increment by 1)
- - - Http request sending test record to api

我遇到的问题是,每条测试记录发送完后,计数器都不会重置,因此第一条记录可以正常工作(5次迭代),第二条记录在第一次迭代时停止.

The problem I am getting is that the Counter is not resetting after each test record is sent through, so the first record through works fine (5 iterations), the second stops at the first iteration.

我尝试过: 1)在用户定义的变量中设置计数器 2)使用beanshell重置计数器元素(这根本不起作用)

I've tried: 1) Set counter in User defined variables 2) Reset counter element using a beanshell (this didn't work at all)

我的测试使用具有单个用户线程的单个线程组.我的csv文件中的每条记录仅在系统中运行一次.

My test uses a single thread group with a single user thread. Each record in my csv file is only run through the system once.

如何成功重置每个记录的计数器?

How do I successfully reset the counter for each record?

推荐答案

  1. 如果您的迭代"来自线程组只需这样做:

如果您的迭代"不是由线程组驱动的,而是来自 Loop Controller ,您可以通过以下Groovy脚本重置计数器:

If your "iterations" are not driven by Thread Group and come from i.e. Loop Controller you can reset the counter by the following Groovy script:

vars.put('Counter', '1')

您可以在 JSR223测试元素或 __groovy()函数中可用,因为

You can use the above script in any of JSR223 Test Elements or in __groovy() function available since JMeter 3.1. In the latter case you will need to escape the comma like:

${__groovy(vars.put('Counter'\, '1'),)} 

这篇关于Jmeter-循环计数器在while循环中,不会在退出时重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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