JMeter Once Only Controller at the end

被刻印的时光 ゝ 提交于 2021-02-10 18:02:07

问题


I would like to perform a certain action per thread, so, I assume that tearDown Thread Group will not work.

Is there any alternative to run Once Only Controller only if it is the last iteration of a thread?

Thanks.


回答1:


  1. Add If Controller to your Test Plan.
  2. Use the following Expression as the If Controller's Condition (assumes __groovy() function):

    ${__groovy(ctx.getThreadGroup().getSamplerController().getProperty('LoopController.loops').toString() as int == (vars.get('__jm__Thread Group__idx') as int) + 1,)}
    
  3. Put Sampler(s) you would like to execute at the end as a child(ren) of the If Controller




回答2:


Add If Controller and check the following condition that current iteration is last. For example if therer are 10 iterations (loop count):

 ${__groovy(10 == vars.getIteration())} 

If you have a variable holding number of iteration, check against variable as myIteration

 ${__groovy(vars.get("myIteration").toInteger() == vars.getIteration())}


来源:https://stackoverflow.com/questions/50023824/jmeter-once-only-controller-at-the-end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!