Writing an Apache JMeter scenario is not an easy task. Debugging a scenario is even harder.

One might think that JMeter is simply recording some browser actions and that’s it, and you are good to go for a load test. This could be valid if the scenario does not require any login.

When it does require login, there will be some dynamic results to parse with the help of regular expressions. RegExp is very powerful and you can find plenty of web sites to test a regular expression against a text.

No Match

When there are multiple matches, for example a list of choices in your webapp, you might want to loop on these with For Each or Loop controller. What if you regular expression is wrong and does not return anything?

This is not easy to troubleshoot as is. Luckily, there are a few options to help you there. I will go through three of them.

View Result Tree

Once you have added a View Result Tree listener, you will be able to run your scenario and see all steps of it in the tree windows. From there, you will be able to see request and response data and, for our part, test the regular expression. This can be achieved by typing it and tick Regular exp. box:

If the step matches your RegExp, then you are good. Nevertheless, at this stage, you are not certain that the target variable contains exactly what you need.

Debug Sampler

Another method, which I find better, is the Debug sampler. You can find it under Sampler menu:

In the step properties, ensure that JMeter variables is set to true:

For example, the scenario I have created in Apache JMeter Playground blog post:

You can see the links array variable with each element “_1“, “_2“, etc. If I go up to the end of the links, I can even see another useful variable which I did not know (links_matchNr):

This “links_matchNr” contains the actual size of the array which can be handy to loop on array.


JSR223, also known as Scripting for the Java Platform, allows to do more complex debugging as well as computation, creation and updates of JMeter variables.

So, a typical JSR223 sample used for debugging will look like this:

The script section is composed of two lines:

  1. line 1 is to retrieve content of link_matchNr variable so that we can use it in script
  2. line 3 is to add a line into the JMeter log viewer

Before running the scenario, I display the log viewer by going into Options menu and ticking Log viewer.

Once I execute the scenario, I can see in the log viewer the following content:

2023-11-29 10:42:41,916 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-11-29 10:42:41,932 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-11-29 10:42:41,932 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-11-29 10:42:42,054 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-11-29 10:42:42,054 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-11-29 10:42:42,054 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2023-11-29 10:42:42,054 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2023-11-29 10:42:42,054 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-11-29 10:42:42,054 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-11-29 10:42:42,054 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-11-29 10:42:42,086 INFO o.a.j.p.j.s.J.JSR223 Sampler: links size: 100
2023-11-29 10:42:43,106 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-11-29 10:42:43,106 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-11-29 10:42:43,106 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-11-29 10:42:43,106 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Line 11 shows the wanted log message “links size: 100“.

My Favorite is …

For most of my use cases, or should I say “problems“, my first choice is the Debug sampler as I can see all defined variables and their values including arrays. I can also detect miss-spell or wrong case.

And you, what is your preferred option? Any of these or even another I did not list?