1
votes

I really need your help. In JMeter 4.0 in my JMX script, I tried to create and increase counter variable and I do that with the BeanShell Sampler before the sampler in while loop. The problem that the counter value himself increased but the sampler takes the wrong value from him, not the updated value. Much thanks for all of you. Or.

enter image description here

enter image description here

enter image description here

1

1 Answers

2
votes
  1. Amend your code to look like:

    temp = Integer.parseInt(vars.get("counterPlugin")) + 1;
    vars.put("counterPlugin", String.valueOf(temp));
    log.info(vars.get("counterPlugin"));
    
    1. Since JMeter 3.1 it is recommend to use JSR223 Test Elements and Groovy language for any scripting operations so consider migrating to JSR223 Sampler
    2. Since JMeter 4.0 you have ${__jm__Loop Controller__idx} variable which holds the current iteration number of the Loop Controller

      JMeter Loop Controller and Counter