1

I have my HTTP request and have some conditions need to wait get at least 1 results or complete=true from the response, but also i want to add if keep executing to satisfy the below condition i want to stop after some request. My code

if (vars.get('complete') == true || vars.get('total_result') > 0) {
    vars.put('stop', true);
}

enter image description here

My request : enter image description here

1

You have a significant number of errors in the jmeter.log file:

enter image description here

so first of all you need to analyze what's going on there, it might be the case the variables are not having respective values.

Also since JMeter 3.1 you're supposed to be using Groovy language for scripting so consider migrating from JavaScript, moreover it is not available in later Java versions

Also JMeter Variables are stored as Java Strings so you need to perform the strings comparison or conversion of values to the required types

Suggested clause change (again assumes Groovy language):

vars.get('complete') == 'true' || (vars.get('total_result') as int) > 0
3
  • thanks for reply, my script is working fine to compare >0,my question here some time my API won't give response(it always total result= 0 and complete==false) so this case script always looking for condition instead i need to stop the particular thread after some number of requests, the errors in above i added extra script to validate this and getting error – Sinu Reddy Mar 2 at 6:48
  • While Controller exposes __jm__While Controller__idx variable since JMeter 5.0 so you can check the current iteration and if its higher than your threshold - exit the loop. If for some reason you stuck on earlier JMeter version - you can use Counter element – Dmitri T Mar 2 at 6:58
  • Thanks Dmitri, working fine – Sinu Reddy Mar 2 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.