How to run a JMeter test from the command line

To run a JMeter test from the command line, we need to follow the steps below:

  1. Open a terminal or command prompt.
  2. Navigate to the directory where the JMeter executable file is located.
    • In our case, the file is inside the JMeter’s bin directory /opt/jmeter/bin. If we have added the directory that contains the jmeter command to our system’s PATH environment variable, we can run the jmeter command from any directory.

      Note: To find the full path of our saved file in the current directory and its subdirectories, we can use the find command in the following manner: find . -name "test.jmx" where test.jmx is the name of our executable file.

  3. Enter the following command to run the test:
    jmeter -n -t /path/to/your/test.jmx -l /path/to/save/results.csv
    

Let’s take a look at how we can do this.

Run the test.jmx file

To add the directory (/opt/jmeter/bin) to the PATH environment variable permanently (not just for the current session) from the terminal, enter the following command:

echo 'export PATH="$PATH:/opt/jmeter/bin"' >> ~/.bashrc
source ~/.bashrc
  • Line 1: The echo command appends the export PATH="PATH:/opt/jmeter/bin"' >> ~/.bashrc line to the end of the .bashrc file[object Object] in the user’s home directory (~ refers to the user’s home directory). This sets the PATH variable for the current user and allows the jmeter command to be executed from anywhere in the terminal.

  • Line 2: The source ~/.bashrc reloads the .bashrc file in the current shell session so that the updated PATH variable is available for the current session.

To gain hands-on experience, please run the above commands in the following terminal to add the bin directory to the PATH environment variable.

Terminal 1
Terminal
Loading...

If we want to run the test.jmx file and place the test results in the result.csv file that we have already created in the JMeter’s bin folder, we enter the following commands:

# command to run the JMeter test
jmeter -n -t ./opt/jmeter/bin/test.jmx -l result.csv
# command to display the contents of the CSV file (result.csv) in a human-readable format
csvtool readable result.csv

In the code above:

  • -n specifies JMeter to run the test in a non-GUI (CLI) mode

  • -t specifies the path to the JMeter test file (.jmx)

  • -l specifies the path to save the test results file

  • csvtool displays the .csv file in the terminal in a human-readable format with headers for each column

We have included the commands above in the terminal below. Click the terminal to see the tests being executed.

Terminal 1
Terminal
Loading...

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved