In our previous JMeter post, we have learned how to reuse and maintain our scripts. So far we have learned enough to create a simple performance scripts for any application but what about the control over the requests and order of execution of requests. Logic Controllers provide the feature to do that.
As we have already learned how to create performance scripts in our previous post (Creating first JMeter script), now we will directly see how to add logic controller and their use.
Follow the steps to add logic controllers:
Test Plan >> Thread Group >> Add >> Logic Controller
You can see there are multiple types of logic controllers available in JMeter.
Simple Controller: This controller just provides the storage for samplers and other logic controllers and this controller has no extra functionality except storage.
In the above image you can see how simple controller is being used to separate the different transactions; it makes the performance scripts much understandable and manageable.
Loop Controller: This controller allows JMeter to iterate any sampler or controller added to loop controller to a certain number of times.
You can set the Loop Count as Forever or number. There is a loop count field in Thread Group as well but it behaves slightly different. Unless set to Forever, it stops the test after the number of iterations have been done.
Once Only Controller: This controller tells JMeter to execute only once. All the controllers inside the once only controller will execute only once for all the threads. It is helpful when you need to run your scripts for a fixed duration and you don’t want to repeat the login transaction again and again. You can simply put the login transaction under the Once only controller and the controller will take care of it (It will only execute once for each thread). See the below image which is showing how to use a login transaction controller inside a Once Only Controller:
Throughput Controller: The Throughput controller allows the user to control how often it is executed. There are two modes to control the execution:
1. Percent Execution: Percent execution causes the controller to execute a certain percentage of the iteration throughout the test plan. User can define the percentage in test plan user defined variable area and use those variables in throughput controller.
2. Total Execution: Total execution causes the controller to execute it for a certain number of iterations. It will stop just after the defined numbers of executions are done.
See the above image in which a transaction is kept under Throughput Controller and execution mode is set to Percent Execution with a value of 40. It tells JMeter to execute this particular transaction 40% of the total test plan.
Runtime Controller: The runtime controller controls how long its children are allowed to run. Just enter the time in seconds to which elements of the controller will execute.
If Controller: The ‘If controller’ allows the user to control whether the test elements below it will run or not.
Here in the above image you can see the condition field, in which the value of count variable will be evaluated and decision will be made. If the condition returns true, it will execute the inside part of If block else will exit the If block.
Module Controller: As the name is self-explanatory, it provides modularity to the JMeter. It provides mechanism for substituting the test plan fragments into the current test plan at run-time. The module controller then can be used to switch between multiple test cases simply by choosing the appropriate controller from the tree. This provides executing many alternate test plans quickly and easily.
As
you can see in the above screenshot that module controller shows the complete
test plan except the module controllers. Now you can easily select the desired
controller to execute. For example: Login and Logout actions are selected
respectively.
This
controller is very helpful in case you have to test different scenarios, you
can quickly and easily select the alternate test cases and execute.
All
of these controllers are most commonly used controllers.
Please like or comment if you liked the post.
Stay tuned to see more posts.
Facebook Page: https://www.facebook.com/crazzzygig
References: http://jmeter.apache.org/