How To Use JMeter For Load Testing

If you are planning to use JMeter as a load testing tool, you might want to create and convert your tests into a JMeter format. This blog will guide you through the process so that you will be able to perform the transition smoothly and within minimum time.

Step 1:

Installing JMeter:

To start with,

  • Use the link to download JMeter to your local machine.(http://jmeter.apache.org/download_jmeter.cgi)

  • Extract it to your preferred location.

  • Open the extracted folder and go to apache-jmeter-3.1> apache-jmeter-3.1>bin> ApacheJMeter( executable jar file).

  • Install Blaze meter extension for Google chrome which will be used for recording and converting the tests. (https://chrome.google.com/webstore/detail/blazemeter-the-load-testi/mbopgmdnpcbohhpnfglgohlbhfongabi?hl=en)

Step 2:

Test Recording and Conversion:

  • BlazeMeter’s Chrome extension lets you record the test and the extension offers two modes: Record and Follow Me.In this Post, we will focus only on the Record Mode.This mode creates a JMeter script and export it as a JMeter .jmx file.

  • Once the installation is done, click the BlazeMeter icon on your chrome browser.

  • If your browser isn’t logged into your BlazeMeter account, click Login. If you don’t have an account, simply register for a free BlazeMeter account.

  • Give your test a name.

  • Check and edit the advanced options as per your requirements.

  • Click the ‘Start’ button.

  • Browse through your application for the business flow that needs to be load tested.

  • Use the ‘Pause’ button to pause in between recordings or, once you’ve finished recording, click the ‘Stop’ button.

  • Click the ‘Edit’ button to edit the recording before uploading it. A new window will open with recorded steps.

  • Click the ‘Export’ button in the Chrome plugin to directly export the recording to a JMeter format.

 

Step 3:

Executing the Recorded Tests:

Jmeter tests can be executed in two methods, one is using JMeter GUI and another is using the command line(Non-GUI)which is preferred.The GUI mode of JMeter is perfect for adding and editing new configuration elements, thread groups, and samplers as a result of which you can view a number of different listeners helping for debugging.

Method 1(Using GUI)

  • Open ApacheJMeter from the bin folder which is Executable Jar File (.jar) and then export the.JMX file to it.

  • Click on the Thread Group and add the following:

  • Set up the load: 5, 10, 15 etc( No of users)

  • Add Summary report, Graph reports for the results.

  • Run it.

  • Click to view the results from summary report file, which can be downloaded as .csv files.

 

Method 2(Using Command line):

However, the GUI mode does have a limitation which slows down the CPU utilization while running the recorded script. If we are running multiple listeners in a script, it affects the JMeter performance. To overcome such a situation, the script should be run in the non-GUI mode. There is a benefit to drive more requests per second out of JMeter in non-GUI mode.

  • Open command prompt

  • Go into JMeter’s bin folder

  • Enter following command, JMeter -n –t (path of JMeter test) -l testresults.jtl

Once your test is complete, you will see the following display:

 

After completing the test, a JTL file will be generated at JMeter/bin folder

Follow below steps to view test results from the resultant JTL file.

  • Open JMeter in GUI mode.

  • Add any listener Eg. View Results Tree.

  • Click Browse button of the file name field in a listener.

  • Opentestresult.jtl file.

  • You should be able to see the result in listener now.

HTML Reports:

Reports are important in any tests, as JMeter has various options to get the reports using plugins but those are not in HTML format. Here are the steps to achieve HTML reports.

  1. Create a folder to save Results. Inside the Results folder, create another folder Named HTML to save HTML result of the test.

  2. Use the below command and Run it.

    cd C:\Users\HR\Desktop\apache-jmeter-3.1\bin(location of jmeter in your local machine)

    set jmeter.save.saveservice.output_format=csv\

    set jmeter.save.saveservice.print_field_names=true\

    jmeter -n -t C:\Users\HR\Desktop\Tests\Test2.jmx(Location of test) -JUSERS=1 -JRAMP_UP_PERIOD=0 -l C:\Users\HR\Desktop\Results\test1.csv(Location of Results folder) -e -o C:\Users\HR\Desktop\Results\HTML\(location of Html result folder)

After executing the batch file, the command window will close automatically and results are saved in the specified folder as excel sheet and HTML link. If you open HTML link, the report will look like this and you can explore the HTML report by clicking on Dashboard and Charts options.