Updated February 21, 2023
Introduction to JMeter Command Line
JMeter is an open-source tool used to perform load and performance testing on the application. There are two ways to use JMeter: the graphical user interface and command line mode. JMeter provides different functionality when we use command line mode, such as we can generate the CSV or say that the XML file consists of the output of test execution. In other words, we can say that it stores the result of the HTML report. Normally JMeter, by default, provides the summary of load testing after the execution as well as we can also see the real-time output of test execution as per our requirements.
What is the JMeter Command-Line?
Apache JMeter is an open-source testing application. JMeter capacities to examine and gauge the presentation of web applications with an assortment of different administrations. In addition, the GUI method of JMeter is ideal for adding and altering new arrangement components, string gatherings, and samplers, which allows you to see various audience members helping with troubleshooting.
Nonetheless, the GUI mode has a constraint that dials back the CPU while running the recorded content. Assuming we are running different audience members in content, it influences the JMeter execution. The content should be run in non-GUI mode to defeat such a circumstance. There is an advantage to driving more demands each second out of JMeter in non-GUI mode.
A command-line interface (CLI) processes orders to a PC program as lines of text. The program that handles the connection point is an order line translator or order line processor.
Working frameworks execute an order line interface in a shell for intelligent admittance to working framework capacities or administrations.
We will execute the JMeter Tests in Non-GUI mode. However, before that, we want to comprehend why we want to execute the Test In Non-GUI mode.
Typically when we execute the Request in the Non-GUI Mode, it will send a few solicitations to the server and get the reaction, and again it will require some investment to produce the reports and view the outcomes to the client. So it will interact with the UI of some sort or another Level.
So we cannot get the Actual outcome when we send the solicitation and help a reaction through UI. So we run the JMeter Test in order briefly to keep away from that circumstance.
Now let’s see why we need to use command line mode.
- Expanding strings (after a specific limit) because of which JMeter crashes in the GUI mode.
- For serious test situations (ex: shopping application: login-view item put on truck view tab eliminate item take care of bill), JMeter consumes memory and CPU, which might influence your experimental outcomes.
- To build JMeter capacities, for example, to get more demands each second.
How to Run JMeter Command-Line?
Now let’s see how we can run JMeter on command line mode.
First, we need to open the command line prompt window, as shown in the following screenshot.
In the second step, we need to go into the bin folder of JMeter. After that, we need to enter the command,
JMeter -n –t test.jmx -l testresults.jtl
We need to set the different parameters in the above command as follows.
- n is used to specify the JMeter run test into a non-GUI mode that is command line mode.
- t Is used to specify the name of the JMX file that contains the plan of a test, and it depends on the user.
- l It is used to specify the name of the JMeter text log file and consists of the log result.
- j It is used to specify the name of JMeter log files.
After executing the above command, we see the generated result in the specified location in CSV format; here, we can add any listener as per our requirement, but we need to open JMeter into a GUI mode for that purpose.
JMeter Command Line Configuration
Now let’s see how we can configure the command line mode of JMeter as follows.
In the above point, we already discussed how to run the JMeter command line mode, but if we want to run JMeter for distributed testing, we need to do some settings on our local machine.
- First, we need to ensure we installed the updated version of JMeter.
- After that, we need to make some changes to the JMeter properties file for IPs and slaves; in this step, we also ensure the master and slave are located on the same subnet.
- Now we need to execute the JMeter server on every slave, so for that purpose, we need to execute the bat file of JMeter from the bin folder.
- Report generation and reaming all things are the same.
Example of JMeter Command Line
Now let’s see the example for better understanding as follows.
First, we need to add the test plan into the JMeter, as shown in the following screenshot.
We need to add the listener to view the output, as shown in the following screenshot.
Now save the test plan, minimize the current window and execute the below-mentioned command.
JMeter -n -t D:\Software\apache-JMeter-5.4.1\apache-JMeter-5.4.1\bin\ View Results Tree.jmx -l D:\Software\apache-JMeter-5.4.1\apache-JMeter-5.4.1\bin\result.csv
Explanation
In the above command, we specify all parameters such as the name of the test plan, location of the test plan, where we need to store the result of the test plan, etc. Then, we can make the changes in the above command as per our requirements. We illustrated the final output of the above command by using the following screenshot.
After executing the above command, the CSV file generated, as shown below, is as follows.
Now we need to open that file to see the output of the test plan, as shown in the following screenshot.
Conclusion
We hope from this article you learn more about the JMeter command line. From the above article, we have taken in the essential idea of the JMeter command line and see the representation and example of the JMeter command line. Furthermore, this article taught us how and when to use the JMeter command line.
Recommended Articles
This is a guide to JMeter Command-Line. Here we discuss the definition and how to run and configure JMeter Command-Line along with the example. You may also look at the following articles to learn more –