I\'ve encountered a problem when trying to update a Jmeter variable with a beanshell script. I\'ve followed this manual and i have seen this topic and both say the same:
I do not see any issues in your script. It should work fine.
Remember that all these beanshell variables are specific to the thread. Ie, If Thread1 increments it to 2, the current value of 'counter' for the Thread2 will still be 1.
I think you run your test for more threads/users with only one iteration. This is why it prints 2 for all users. If you have more loop counts/set it to forever, counter will get incremented.
You can upload your jmx file if it still does not resolve the issue.
EDIT:
I just checked your jmeter test. Even though you increment the counter value by 1 in the Beanshell Sampler, Yolu are setting the counter back to 1 as part of User Parameters
. Remove it. After removing them, It works fine for me.
Put the cookie manager in your script and you will be fine.
Now you have a global variable counter = 1, in one request you use a local variable counter ant set it to 2. When another request tries to pick up the value of counter it gets the global value 1, because the local one is trashed.