Performance · Technical

Jmeter – command line script execution with arguments


Its a common practice to create Performance script in GUI mode and run the test in CUI (command user interface) mode. Some time we need to pass some arguments to script as input. Using GUI, we can change the property any time but how can we achieve this using command line? We can achieve this via passing additional arguments.

Scenario: Passing users/thread count and duration of test run using command line. At the end of this blog, we will be able to

  1. Pass user/thread count as a parameter from command line
  2. Run a test plan for certain amount of time
  3. Pass plan duration as a parameter from command line

Solution:

Use JMeter properties to use command line parameters. see the image below:

Jmeter Thread Property to pass arguments commandline
Jmeter Thread Property to pass arguments commandline

As you see, i have used

${__P(<variable name>,<default value>)}

to read command line property in JMeter. To pass value as arguments, the command will be:

jmeter -n -t PerformanceTest.jmx -Jusers=4 -Jduration=300

Here i have used -J<property name> option to use custom parameters. So

  • to read user count, set Number of threads (users) as ${__P(users,2)}
  • to set test execution duration, set Duration (seconds) as ${__P(duration,2)}
  • pass value using command prompt jmeter -n -t PerformanceTest.jmx -Jusers=4 -Jduration=300

All the best!

Reference: http://jmeter-tips.blogspot.in/2010/01/tip-4-using-jmeter-properties.html

Advertisements

7 thoughts on “Jmeter – command line script execution with arguments

  1. Well I tried to do it by this nice guide, but unfortunately it won’t run 😦
    It shown me error:

    Error in NonGUIDriver java.lang.NullPointerException

    Do you know how to handle it?

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