0
votes

Goal:

I would like to visit 10 different URLs of the form http:localhost/path/item/${id} where id is a Random Variable. For each of these URLs, I want to request them until the response returns a specified string.

Current setup:

I have a While Controller with an Http Request under it. The condition looks like ${__javaScript('${response}'.indexOf("my string") == -1,)} (the response variable is saved via a JSON Extractor). I also have the Loop Count in the Thread Group set to 10.

Problem:

My test plan works fine, but only for one URL. It's as if it's ignoring the Loop Count setting. Assuming the While Controller makes two requests per URL, it's only making two requests total, rather than expected 20.

This is puzzling because if I use a Loop Controller with a Loop Count of 5, it makes 50 total requests.

How can I achieve the desired behavior?

1

1 Answers

1
votes

Cannot be 100% sure without seeing the whole plan, but I suspect it's because you are not unsetting ${response} for next iteration, after it reaches true condition. I.e.

  1. First iteration starts, and ${response} is empty/undefined ==> enters while
  2. At some iteration within while it sets ${response} so, that ${__javaScript('${response}'.indexOf("my string") == -1,)} gives true ==> While exits
  3. Next iteration starts. If at this point ${response} is still the same as in previous iteration, it will never enter while, since it's already true.

If this is the case, reset value at the beginning of iteration.

To reset the value, add a BeanShell Sampler nd either remove a variable:

vars.remove("response");

or set its value to empty / something else:

vars.put("response", "");

If this is not the problem, look for exceptions in the jmeter.log. Could be that your script is exiting due to error.