Run JMeter in Command Line

A command-line interface (CLI) processes commands to a computer program in the form of lines of text. The program which handles the interface is called a command-line interpreter or command-line processor.

Operating systems implement a command-line interface in a shell for interactive access to operating system functions or services.

We are going to execute the JMeter Tests in Non-GUI mode. Before that, we need to understand why we need to Execute the Test In Non-GUI mode.

Normally when we execute the Request in the Non-GUI Mode, it will send some requests to the server and get the response, and again it will take some time to generate the reports and view in the results to the user. so it will do some kind of process in the UI Level.

So we can not get the Actual result when we send the request and getting a response through UI. To avoid that situation we run JMeter Test in command prompt.

  • Basically GUI consumes more Memory/Resources.
  • And, GUI not recommended for heavy load testing because we will not get accurate results.
  • When we run the JMeter through the command line it can also be integrated with other systems-Jenkins and other continuo s integration tools.

The following example demonstrates how to run the JMeter in the Command-Line.

  • The First step is to open the JMeter and create a Test Plan.
  • And then add Thread Group to the Test Plan and add HTTP sampler request to the Thread group.
  • Next, open the Orange HRM application, and copy and paste the URL in the HTTP Request.
  • Next, set the Thread Group to 5.
  • Now we are not going to add any listener to view the result.
  • Save the Test Plan and minimize the JMeter window.
  • Our Test Plan has been saved in a bin folder.
  • Open the bin folder where your Test Plan has been saved and open the command prompt in the same folder.
  • The command syntax to run the Jmeter Test Plan is as below.
    Jmeter -n -t (location of your JMeter test script) -l(location of the result file)
    -n=Non GUI Mode
    -t=Location of JMeter Script
    -l=Location of result file​
  • Now let us execute the Test plan.
    The Command is as shown below: 
    jmeter -n -t D:Jmeter_Projectapache-jmeter-5.2.1inMyPlanscommandline.jmx -l D:Jmeter_Projectapache-jmeter-5.2.1inMyPlans
    //** the location of the Test Plan**//
    //**Result File*//
  • The same command I have entered in the Command line as shown below
  • After running the command successfully, the Result file has been created in the given location.
  • If you open the Result file, you will find the following details.
  • We can also execute the command to create a result file in jtl form. The command will be the same but the result file will Result.jtl.
    jmeter -n -t D:Jmeter_Projectapache-jmeter-5.2.1inMyPlanscommandline.jmx -l D:Jmeter_Projectapache-jmeter-5.2.1inMyPlans
  • The Result file has been created in the form of .jtl as below.
  • Now, we can open the jtl file in the JMeter. We can see the result either in Table format or in Graphical format.
  • Open the JMeter and add View Result Tree to the Thread Group.
  • And then click on the Browse in the View Result Tree as shown below.
  • Next, select the Result.jtl file from the folder as below.
  • Now we can see the result in the Tree format.
  • If you want, you can also see the result in the graphical format or in the Table format by adding the Respective Listeners to the Thread Group and then browse the Result.jtl file.

Creating HTML Reports from Commandline

  • Open the JMeter in your system and then add Thread Group and then Three HTTP Request to the Thread Group.
  • And enter the Number of Threads as 5 and the Ramp-up period as 2 and then, the Loop count as 3.
  • Rename the HTTP Requests as HTTP Request1, HTTP Request2 and HTTP Request3.
  • In the HTTP Request1 add blazedemo link in the server and enter the path as /Register
  • Enter the login details in the Second request as below.
  • Enter the root page details in the third request as below.
  • Next, add View Result Tree Listener into the Thread Group to see the report.
  • Enter the Result.csv file path in the view result tree as shown below.
  • Before running the test plan through the command line make sure that the CSV file is not available at the file location. So I am deleting the result.csv file from the MyPlans folder.
  • We are going to execute the command which not only going to create the CSV file, by using the details of the CSV file we also going to create an HTML report.
  • We can create an HTML report in two approaches:
    • To Create an HTML report at the end of the Test : which means, at the time of running the HTTP request we can create the HTML file.
      The Command to create CSV file and HTML report at once is as follow
      jmeter -n -t "D:Jmeter_Projectapache-jmeter-5.2.1inMyPlanscommandline.jmx" -l "D:Jmeter_Projectapache-jmeter-5.2.1inMyPlans
      esult.csv" -e -o "D:Jmeter_Projectapache-jmeter-5.2.1inMyPlanshtmlReports"​
    • Creating an HTML report with standalone CSV file : In this case, we have a CSV file, by using the details of this CSV file we can create the HTML report.
      The Command to create CSV file and HTML report is as follow
      jmeter -g "D:Jmeter_Projectapache-jmeter-5.2.1inMyPlans
      esult.csv" -o ""D:Jmeter_Projectapache-jmeter-5.2.1inMyPlanshtmlReports"
  • Open the Command prompt in the Bin folder of JMeter and then execute the first command as shown below.
  • After executing the command in the command prompt, if you open your file location you will find both Result.csv file and then HTML Report.
  • Now I am going to delete the HTML Report and I have only Result.csv file.
  • Click on the HTML Report you fille below files inside the folder.
  • Click on the Index file you will see the Dashboard, Customer Graphs, and Charts.
  • By using the Result.csv file details I am going to create an HTML report, but this time the Command will be changing a little bit as below.
  • In the folder, you can see that the HTML report has been created.
0 results
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions