To run a JMeter test from the command line, we need to follow the steps below:
/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
findcommand in the following manner:find . -name "test.jmx"wheretest.jmxis the name of our executable file.
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.
test.jmx fileTo 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"' >> ~/.bashrcsource ~/.bashrc
Line 1: The echo command appends the export PATH="PATH:/opt/jmeter/bin"' >> ~/.bashrc line to the end of the ~ 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.
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 testjmeter -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 formatcsvtool 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.
Free Resources