I have been using JMeter for years & I always found that difficult when there is no easy way to exit from the loop in case of error. I was looking for something like break statement in Java inside a while / for loop.
JMeter has If Controller which will let you execute the Samplers based on the condition. So, We can actually exit from the loop by designing the Test Plan with standard controllers available with JMeter.
As part of my project requirement, I had to execute above transactions in the given order. I do the Login first. Then I keep doing all the transactions inside the While Controller again and again. For this requirement, above setup should work well!
But the problem arises, when there is some failure occurs in any of the transactions.
Say, I search for a product. If the product is not available, there is no point in executing other transactions like – Ordering product, entering payment details, viewing product etc!! They are going to fail for sure!!
So, To make the test as I want with standard controllers, I have to design as given below.
Yes, above test plan should work well. But, in this case, I have only few transactions. What if I have 100 transactions? Should I have to add 99 If controllers after the first one!!? Does it not make my test plan very difficult to maintain? Yes, It actually does :(.
So, I wanted to have my own controller which keeps executing all the samplers inside & but checks for the status of the previous sampler/transaction before proceeding. If the previous request passes, send the next request; If any of the sampler/transaction fails, exit from the loop/controller. [Thank God – JMeter is open source & lets us extend it with custom plugins!!]
Why is it called Until Controller? – It keeps executing all the samplers until some failure occurs.
Lets see this example. I have a test plan as given below. (1 thread – runs forever)
When i run the test, I see the output as given below just like I had expected. (Just execute all the samplers inside the until controller again and again).
When some samplers fail, just stop the controller’s execution & exit from the loop. Go to the next sampler after the ‘Until Controller’.
This was exactly as I wanted. So, I can remove all the If Controllers, Create my test plan as given below.
The behavior is almost same like While Controller, I just wanted to compare the performance of Until Controller (logic of the controller should not affect the test’s performance) with while controller.
I had some samplers inside both controllers & ran it for sometime with no timers. They take sametime in both Pass & Fail cases..
If you would like to try, Please download it from here & place the jar under JMETER_HOME/lib/ext
UntilController.zip (505 downloads) Note: It will work only with JMeter version 2.13 or above.