Updated February 21, 2023
Introduction to JMeter While Controller
JMeter provides a different controller for the user to perform load and performance testing per our requirements. The whole is one of the controllers that the JMeter provides. While the controller is used to run the child samplers from the Test Plan, it continues the execution until the condition is false from the condition field. For example, suppose the condition field has a blank value at that time while the controller exits. Normally the while controller is a conditional statement, and it allows us to implement some advanced scenario that means some condition depends on the other scripts.
What is JMeter while controller?
Regarding building a high-level JMeter load test situation that accepts complex rationale, contingent upon specific conditions, it is sometimes expected to change the Sampler’s execution request. Typically JMeter runs every one of the Samplers topsy turvy, yet there could be a few situations when the default conduct isn’t reasonable.
JMeter’s execution of the while controller. For those inexperienced with the whole controller idea, to lay it out plainly, it’s simply a rehashed “if->then” articulation.
In the case something is valid, then, at that point, rehash the last activity
In JMeter, the regulator fundamentally runs kids Samplers, except if some foreordained “Condition” is “valid” where “Condition” could be:
Clear: for this situation, the While Controller will leave when the last sampler insider savvy falls flat
LAST: equivalent to clear, yet with an extra check for the last Sampler before the controller result. If the previous Sampler isn’t effective, the While Controller and its youngsters will not be executed.
Function or Variable JMeter: The Controller’s kids will run until a variable or capacity assessment result is “valid.”
Property of JMeter: equivalent to Function or Variable, yet expects the Property all things being equal
Both the Function/Variable and Property approaches expect that the “Condition” will be set to “bogus” someplace in or outside the controller. On account of Property, it very well may be done from another Thread Group or even external JMeter.
The initial 2 cases with “clear” and “LAST” are straightforward. Assuming you leave the “Condition” clear or set it to LAST, the controller will break if the last sampler under the While Controller isn’t fruitful. Similar applies to the Variables and Properties. The While Controller will control its youngsters until the Variable or Property determined in “Condition” will bring about “validity.”
How to use JMeter while controller?
Now let’s see how we can use the while controller in JMeter.
We know that while the controller runs the child until the condition is false.
First, we need to consider some possible conditions as follows.
Blank: Blank means it exits the loop when the last sample fails.
Last: means it exits the loop when the last sample fails.
Condition
The condition means variable or function, and while the controller requires true or false, that means, as per our requirement, we can set the condition.
First, create the Test Plan as per our requirement; here, we created the Test Plan as shown in the following screenshot.
Now add the Thread Group and sampler; here, we add the HTTP request sample as shown in the following screenshot.
Here we add a dummy API with a view result tree, as shown in the following screenshot.
As shown in the following condition, we must add the condition to implement the while controller.
First, while the controller, we can check with blank as shown in the following screenshot.
After executing the Test Plan, we can view the output in the view result tree, as shown in the following screenshot.
Now set the same condition as per our requirement; here, we set the counter value as follows.
${__javaScript(parseInt(vars.get(“counter”))<=50)}
After execution, we can set the result in the following screenshot.
Here we can access the dummy URL from the CSV file, which can be accessed through the variables.
JMeter while controller Functions
Now let’s see while the controller functions as follows.
We know JMeter provides the different types of inbuilt functions for the user to implement, while controller is as follows.
- Information
Under the information type, JMeter provides the different functions as follows.
- thradNum: If we want to get the thread number, then we can use this number.
- samplerName: It is used to get the name of a sampler.
- Time: It returns the system’s current date per our required format.
As well as information type provides the log, logn, machinelp, and machineName functions.
- Input
Under the input type, JMeter provides different functions as follows.
- StringFromFile: It is used to read the text from the file.
- FileToString: If we require reading the entire file, we can use this function.
- XPath: It is used to read the XPath expression from a file.
- CSDVRead: It is used to read the CSV file.
- Calculation
Under calculation, JMeter provides the different types of functions as follows.
- Counter: If we want to increment the number at that time, we can use this function.
- intSum: It is used to add the integer to the number.
- longSum: It is used to add the long integer number.
- Random: By using this function, we can generate a random number.
- RandomSring: By using this function, we can generate the random string.
- Scripting
Under scripting, JMeter provides the different types of functions as follows.
- BeanShell: It is used to run the BeanShell script.
- JavaScript: By using this function, we can work on JavaScript.
These are some sample types, and their function and JMeter also provide some additional functions such as Properties, Variables, String, etc.
JMeter while controller Cases
Now let’s see different cases for the while controller as follows.
- While with counter: We can use a while controller to combine with a counter.
- Sampler of Beanshell: Here, we can declare counter value 1.
- While controller: We can check the counter value using the while controller.
- Processor: It is used to increment the counter value.
Conclusion
We hope from this article you learn more about JMeter while controller. From the above article, we have taken in the essential idea of JMeter while controller, and we also see the representation and example of the JMeter while controller. Furthermore, this article taught us how and when to use the JMeter while controller.
Recommended Articles
This is a guide to JMeter While Controller. Here we discuss the essential idea of JMeter while controller, and we also see the representation. You may also look at the following articles to learn more –