Run JMeter in Command Line

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 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 continuous 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.
    adding-http-sampler-request-jmeter
  • Next, open the Orange HRM application, and copy and paste the URL in the HTTP Request.
    http-request-open-source-orange-hrm-jmeter
  • 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.
    test-plans-saved-in-bin-folder-jmeter
  • 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_Project\apache-jmeter-5.2.1\bin\MyPlans\commandline.jmx -l D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\result.csv
    
    Where:
    //** the location of the Test Plan**//
    D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\commandline.jmx
    
    //**Result File*//
    D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\result.csv
    
  • The same command I have entered in the Command line as shown below
    running-the-coomand-in-cmd-prompt-jmeter
  • After running the command successfully, the Result file has been created in the given location.
    result-file-created-jmeter
  • If you open the Result file, you will find the following details.
    result-file-in-excel-format-jmeter
  • 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_Project\apache-jmeter-5.2.1\bin\MyPlans\commandline.jmx -l D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\result.jtl​
  • The Result file has been created in the form of .jtl as below.
    jtl-file-jmeter
  • 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.
    click-on-browse-in-view-result-tree-jmeter
  • Next, select the Result.jtl file from the folder as below.
    open-result-jtl-file-jmeter
  • Now we can see the result in the Tree format.
    view-result-in-tree-format-jmeter
  • 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.

Beanshell in JMeter

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.
    thread-group-number-and-ramp-up-number-loop-count-jmeter
  • Rename the HTTP Requests as HTTP Request1, HTTP Request2 and HTTP Request3.
    http-request-one-two-three-jmeter
  • In the HTTP Request1 add blazedemo link in the server and enter the path as /Register
    http-request-with-blazedemo-jmeter
  • Enter the login details in the Second request as below.
    seond-request-with-login-details-jmeter
  • Enter the root page details in the third request as below.
    root-page-details-in-http-request-jmeter
  • Next, add View Result Tree Listener into the Thread Group to see the report.
    add-view-result-tree-jmeterr
  • Enter the Result.csv file path in the view result tree as shown below.
    enter-csv-file-path-jmeter
  • 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_Project\apache-jmeter-5.2.1\bin\MyPlans\commandline.jmx" -l "D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\result.csv" -e -o "D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\htmlReports"​
    • 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_Project\apache-jmeter-5.2.1\bin\MyPlans\result.csv" -o "D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\htmlReports"
  • Open the Command prompt in the Bin folder of JMeter and then execute the first command as shown below.
    command-to-create-csv-file-and-html-report-jmteerhtml-report-dashboard-and-customerpgraphs-jmeter
  • 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.
    created-htmlreport-and-csv-file-jmeter
  • Now I am going to delete the HTML Report and I have only Result.csv file.
    deleted-html-report-jmeter
  • Click on the HTML Report you fille below files inside the folder.
    files-under-html-repport-jmeter
  • Click on the Index file you will see the Dashboard, Customer Graphs, and Charts.
    deleted-html-report-jmeter
  • 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.
    jmeter -g "D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\result.csv" -o "D:\Jmeter_Project\apache-jmeter-5.2.1\bin\MyPlans\htmlreports"​

    another-command-to-create-csv-file-and-html-report-jmeter
  • In the folder, you can see that the HTML report has been created.
    html-reports-craeted-jmeter
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions