Debugging is, arguably, the most important software development practice. Software doesn’t work immediately upon coding: you need to detect bugs and fix them. Apache JMeter scripts are no exception.
Here are a few useful JMeter debugging methods:
Debugging Regular Expressions
JMeter provides all the features you need to debug your regular expressions. "Regular Expression Extractor" is one of the most used post processors to retrieve source code data. Let's try to write a regular expression and then debug it. We will retrieve the login URL with "Regular Expression Extractor".
Open JMeter and add a "HTTP Request" sampler. Set "blazemeter.com" as the server name and "/" as the path. Add "View Results Tree" and run your test. When the test is complete, open the “View Results Tree” and select “Response data”. Type “Login” in the search field and press “Find next” till you find needed tag.
Now copy the line you found and select “RegExp Tester” from the dropdown menu.
Paste the copied line and leave only <span>Login</span></a>. If you click the “Test” button you can see that expression matched. Now add <a href="(.*)"> in the beginning of expression and click the “Test” button again.
You can see that the regular expression is correct and that it matches the login URL. You can play with “RegExp Tester” when you are not sure if a regular expression is correct. RegExp Tester saves a lot of time and makes debugging easier as you do not need to run your test several times.
To debug CSS/JQuery you can use the previous method by selecting “CSS/JQuery Tester” from the dropdown menu.
Select “XPath Tester” from the dropdown menu to debug XPath expressions. Note that “XPath Tester” is only available on JMeter 2.11, so make sure you’ve downloaded the latest JMeter version.
Real-Time Sampler/Expression Debugging
After testing an expression with “RegExp Tester” you can be sure that that expression is correct and it will work when you run a test. But in some cases it may not work due to dynamic content, testing OK with “RegExp Tester” but not working when you run an actual test. In this case you can easily find the problem with “Debug Sampler”. Add “Debug Sampler” before “View Results Tree” and run the test. When the test is completed open the “View Results Tree” and select “Debug Sampler”. You will see the matched data that will help youfigure out the actual problem.
“Debug Sampler” has three options: “JMeter properties”, “JMeter variables”, and “System properties”. Enabling or disabling these options will print out or ignore properties. “JMeter variables” should be true to debug “Post processors”.
If you want to debug a sampler you need to add “Debug PostProcessor” as child item. “Debug PostProcessor” prints sampler properties which will be useful to find the actual problem in the sampler.
Debugging Using Fake Sampler Generation
“Dummy Sampler” is a plugin which can generate fake samplers with defined values. This sampler makes it simpler to test when you have complex scripts or when running a test takes too much time. All you need is to just copy and paste “Response data” into “Dummy Sampler”. When you run the test, the “Dummy Sampler” generates a sampler with pasted response data.
Let’s see how this plugin works. Create a new test and add “Thread Group”, “jp@gc - Dummy Sampler” and “View Results Tree”. Before running it, increase the number of users and run the test.
The plugin provides several options such as “Latency”, “Response time”, “Response code” and “Request data”. Using these options, you can change the sampler’s values.
Debugging JMeter Elements
All items in the test tree can be debugged by printing the debug log. First uncomment jmeter.loggerpanel.display=true in the jmeter.properties file. This change will open a log viewer each time JMeter is started. In the test tree select any item for which you want to see debug information. Click the “Help” menu and then “Enable debug”. To see the debug information you need run the test.
Create a simple test with “HTTP Request” and add “HTTP Cache Manager”. Select “HTTP Cache Manager” click “Help” -> “Enable debug”. Click “Options” -> “Log Viewer” to see the log message. Now change the loop count to 3 and run a test.
In the “Log Viewer” you can see the debug log of “HTTP Cache Manager”. This is what it looks like:
DEBUG - jmeter.protocol.http.control.CacheManager: GET(OAH) http://demo.blazemeter.com/ null
DEBUG - jmeter.protocol.http.control.CacheManager: inCache http://demo.blazemeter.com/ null
To disable printing debug information, select “HTTP Cache Manager” and click “Help” -> “Disable debug”.
In addition to the debug log you can also print error and info logs. To do that you need to add some lines into the jmeter.properties file. First select the item you want to print logging and click “Help” -> “What’s this node?”. In “Log Viewer” you will see information about the package and the class name, similar to this:
INFO - jmeter.gui.action.What: TestElement:org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy, guiClassName:org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui
Now open the jmeter.properties file and add:
into “Logging configuration” label. To set logging levels you can use these values:
Remote JMeter Debugging
You can debug JMeter remotely with Eclipse IDE. Here are the steps to configure JMeter for remote debugging:
- Download the JMeter archive and extract it in a remote server
- Open the bin folder
- Run command “export JVM_ARGS=-agentlib:jdwp=transport=dt_socket,server=y,address=8000”. Note that port 8000 should be free.
- Run JMeter: /jmeter -n -t tmp.jmx the output should be: Listening for transport dt_socket at address: 8000
Now JMeter is listening to a command to launch a test from Eclipse. Let’s configure the Eclipse IDE to debug JMeter:
- Create new Java project
- Click “Run” -> “Debug configurations”.
- Select “Remote Java Application”
- Click right mouse button and select “New”
- Insert host ip address and remote port number
- Click “Apply”
- Click “Debug”
After clicking on the debug button you can see the running process in the debug panel.
Any questions? Comment? Leave them below.
You might also find these useful:
Interested in writing for our Blog? Send us a pitch!