Howto debug JMeter scripts

In this article we examine debugging options in JMeter. I start from debugging on GUI level which helps during working with “Post Processors”. In this case we will debug “Regular Expression Extractor”. To make it work, add these elements into test tree:

    • Thread group
      • HTTP Request
        • Regular Expression Extractor
      • Debug Sampler
      • View Results Tree

Now you have to configure “HTTP Request” and “Regular Expression Extractor” and the rest of elements leave unchanged. Insert any server name, for example releasecon.wordpress.com in “HTTP Request”. “Regular Expression Extractor” should be changed proceeding screenshot.

screenshot_221

Now try to run your test, open “View Results Tree” and select “Debug Sampler”. On the right pane you see the list of Jmeter variables and also REGEXP variable with value.

screenshot_222

Tips to debug manually with Debug Sampler

  • Disable all unused elements in test tree, as it will take too much time
  • Set all Thread properties values to 1
  • Click Ctrl+E and Ctrl+R – to keep results tree clean

Jmeter Debug logging

 Debug logging can provide more detailed information. By default you can debug any package and any class. So I showed howto debug “Regular Expression Extractor” with Debug Sampler and now I will show howto debug “Regular Expression Extractor” with debug logging. First you need change jmeter.properties and set jmeter.loggerpanel.display=true. After save your script and restart Jmeter. When Jmeter launches you will see log panel.

screenshot_223

Open your previous script, select “Regular Expression Extractor” from test tree and click Ctrl+W. In log panel you see two new strings, this is classpath of “Regular Expression Extractor” processor.

org.apache.jmeter.extractor.RegexExtractor
org.apache.jmeter.extractor.gui.RegexExtractorGui

 Now open jmeter.properties and add line in “Logging Configuration” label:

log_level.jmeter.extractor.RegexExtractor=DEBUG

Restart Jmeter, open your script and try to run it. If you see DEBUG – jmeter.extractor.RegexExtractor message this means debug logging working and you can scroll up to see HTML body, “Regular Expression Extractor” settings.

screenshot_224

It’s not recommended to use such way to debug Regexp patterns, it was just example. But debugging protocols such as HTTP, FTP, JDBC, JAVA wil be very useful, to achieve this just uncomment needed packages in jmeter.properties and change value to DEBUG. For example:

log_level.jmeter.protocol.http=DEBUG
log_level.jmeter.protocol.http.control=DEBUG 
log_level.jmeter.protocol.ftp=DEBUG
log_level.jmeter.protocol.jdbc=DEBUG 
log_level.jmeter.protocol.java=DEBUG

Howto debug Beanshell in Jmeter

When you use Beanshell in your script it maybe difficult to debug it in Jmeter. You can enable Beanshell debug logging with adding log_level.jmeter.testbeans=DEBUG in jmeter.properties.

As result you will get detailed debug information but Jmeter is not IDE and sure not good choice for debugging Beanshell scripts. I decided that best option to debug Beanshell is using native console in standalone mode. Let’s create simple beanshell and lauch it.

$vim helloWorld.bsh

Add this code:

helloWorld() {

System.out.println("Hello World!");

}
helloWorld();

Export Beanshell classpath to use it in console.

cd $APACHE_JMETER/lib
export CLASSPATH=$CLASSPATH:bsh-xx.jar

bsh-xx.jar can be found in lib folder of Jmeter.

Run your script:

java bsh.Interpreter helloWorld.bsh

If you get error similar to this:

Evaluation Error: Sourced file: helloWorld.bsh Token Parsing Error: Lexical error at line 5, column 24. Encountered: "u201c" (8220), after : "":

To fix it change curly quote to simple.

To debug this code add to the first line code:

 debug();

and you code will look like this:

debug();
helloWorld() {    System.out.println("Hello World!");
}
helloWorld();

Run your code:

 bsh.Interpreter helloWorld.bsh

Output:

// Debug: invokeLocalMethod: helloWorld
// Debug: trying to resolve variable: System
// Debug: trying class: System.out
// Debug: Trying to load class: System
// Debug: getClass(): System not	found in NameSpace: helloWorld (bsh.NameSpace@771c8a71) (method) 
// Debug: Trying to load class: java.lang.System
// Debug: Name call to getStaticFieldValue, class: class java.lang.System, field:out
// Debug: getResolvedMethod cache MISS: class java.io.PrintStream - println
// Debug: Searching for method: println( java.lang.String ) in 'java.io.PrintStream'
// Debug: Looking for most specific method: println
// Debug: cacheResolvedMethod putting: class java.io.PrintStream public void java.io.PrintStream.println(java.lang.String)
// Debug: Invoking method (entry): public void java.io.PrintStream.println(java.lang.String) with args:
// Debug: args[0] = Hello World! type = class java.lang.String
// Debug: Invoking method (after massaging values): public void java.io.PrintStream.println(java.lang.String) with args:
// Debug: args[0] = Hello World! type = class java.lang.String
Hello World!
// Debug: End of File!
Advertisements

2 thoughts on “Howto debug JMeter scripts

  1. Pingback: Debugging JMeter with Wireshark | Release/QA/Project Management

  2. Pingback: Using Beanshell for Beginners | Release/QA/Project Management

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s