Apache Jmeter is a pure Java based application designed as Load Testing Tool and for efficiently doing analysis & performance measurement of Web applications or variety of services. Apache Jmeter is an open source Performance Testing tool with some outstanding abilities. In this article we will discuss about how to record and prepare Jmeter script.
Jmeter does nothing but simulates bunch of virtual users and using them to send requests on the target server. It also gathers the response coming from server in form of Tables, Graphs, Result Tree etc.
If you are new to Jmeter, below are some reference links for introduction and to understand some Basic features of Jmeter:
Before we start cooking in Jmeter, Let’s have a look at ingrediants :
– Thread Group
– Recording Controller
– HTTP Request Defaults
– HTTP(S) Test Script Recorder
– View Result Tree
– Summary Report
Step 1 – Opening Jmeter in GUI mode
– Go to Jmeter installation directory.
– Open Apache Jmeter Folder.
– Under Apache Jmeter, you will see a folder named “bin”.
– Now to open Jmeter window you can double click “ApacheJmeter.jar” or “jmeter.bat” file from the folder “bin”. Below displayed image is the Jmeter 3.0 default screen.
Step 2 – Add Thread Group
– Thread Group is added to the Test Plan from this option which acts as starting point of any Jmeter Performance script. To add Thread Group, you will need to Right Click on Test Plan and Threads(Users) > Thread Group. To read about Thread Group in detail, click here.
Step 3 – Add HTTP Request Defaults
– We are always dealing with multiple HTTP Requests to the same web server. So by using HTTP Request Defaults we can define Server Name, Port number(optional) and Parameters to send with the request. Now we don’t have to pass the same information for each HTTP Request.
To Add, Right Click on Test Plan > Add > Config Element > HTTP Request Defaults.
Step 4 – Add Recording Controller
Recording Controller is a place where Jmeter would like to store all the recorded HTTP requests by default. It is not mandatory to add recording controller. You can directly save all the requests under thread group.
To Add, Right Click on Thread Group > Logic Controller > Recording Controller.
Step 5 – Add HTTP(S) Test Script Recorder
Earlier known as HTTP Proxy server, this element allows Jmeter to record the actions while you browse web application on actual browser. Jmeter will create samples for each request and store them under Test Plan.
To Add, Right Click on WorkBench > Add > Non-Test Elements > HTTP(S) Test Script Recorder.
Now we have everything in place and not it’s time to do some required configuration before starting the actual recording.
Configuration to Start Recording with Jmeter :
– Open HTTP Test Script Recorder and change following parameters as displayed in below image.
1) Port = 8080
2) Target Controller = Recording Controller
3) URL Patterns to Exclude = Click “Add Suggested Exclude” button
– Open the browser through which you wish to record your Jmeter script. For example, in Mozilla Firefox Go to Tools > Options > Advanced Tab > Network > Settings.
– Now Under Settings screen, select Manual Proxy Configuration: and provide HTTP Proxy as localhost and Port as 8080(same as provided in HTTP(S) Test Script Recorder).
Start Recording Jmeter Script :
We will simply record Testing Journals Landing Page and run with Thread count = 1.
Note : Do not perform Load/Stress test on any websites without approval. That’s their production environment and it could hurt them on big level.
– Click Start button on HTTP(S) Test Script Recorder.
– Open Mozilla Firefox browser(where we have already done network settings) and Hit the URL : www.testingjournals.com in the browser.
– Now open recording controller under Thread Group in Jmeter script and you can see multiple requests have been recorded.
– Go to HTTP(S) Test Script Recorder and click Stop button. It will stop the recording your activity on the browser. Your Jmeter Script will look like this :
Let’s Run your First Jmeter Script
To capture the response we will need to add a Listener. There are many listeners available in Jmeter but we will just add a View Result Tree.
To add, Click on Test Plan > Add > Listener > View Result Tree.
And finally, set the Number of Thread = 1 in Thread Group and Click on the Play Button from the Top Bar. Your execution will start with 1 virtual user and now you can see the response in View Result Tree.
So, we are now done with the preparing a basic Jmeter Script. Did you find this article useful? or Got any suggestion? Please let us know via comments. Happy Testing!!