Performance Testing of Websites Using JMeter
In this tutorial, we will be studying the creation of a Performance Test Plan for Web Applications using which we can do performance testing of websites using JMeter. We will also get to know about the different test plan elements required for creating the test script along with their usage and configurations.
Pre-requisites for a Performance Tests
The following things should be known beforehand while creating performance test plan for web applications-
- Knowledge of application’s business scenarios.
- An application instance dedicated for performance testing with configurations and state similar to production.
- List of scenarios selected for performance testing (as not all scenarios are required to be load tested).
- The peak load in production or the anticipated peak load value.
- The user distribution across different scenarios as some scenarios are more frequently used than others. Hence, different number of user count is assigned to different scenarios.
- The value of think time or wait time to be included in between some operations for simulating real users – thinking time, typing time, reading and information processing time etc.
- The performance test metric to be derived from test results like response time, Hits per Second etc.
Steps involved in creating a Performance Tests Scripts
The following steps need to taken in order to create a performance test plan for web applications-
- Creation of a Test Script Skeleton having Test Plan, Thread Groups and Logic Controllers Configured.
- Creation or recording of HTTP Requests using HTTP Proxy Server.
- Adding Timers for introducing wait time or think time between requests.
- Adding listeners for storing and analyzing test results.
- Dry run of test with 1 or 2 users.
- Configuration of the load test with the required number of users and run it.
- Running and analyzing the test results.
Now, let’s see how we can perform each step mentioned above in detail.
Creation of a Test Script Skeleton
Based on the number of user groups required for performing different operations, we will add Thread Groups and Logic Controllers to our Test Plan. For example – if we have two sets of users performing searching and login operations on a website.
Then we will create two Thread Groups and add different Logic Controllers to simulate the different operations performed by the users. Steps to perform-
- Add a Thread Group to the test plan and name it UsersSearchingKeywords.
- Add multiple transaction controllers as child of this Thread Group and name them as per the operations they perform like – “Launch application”, “Search a Keyword and hit enter”, “Close the Application”.
- Add another Thread Group and name it UsersLogin.
- Add transaction controllers to this thread Group like – “Launch application”, “Click on Login Link”, “Enter credentials and click Submit”.
Add the of configuration our test plan will look like this-
Please note that we have used the transaction controller here, as within this controller we can have multiple HTTP requests and after the test execution, we will get the overall response time of the whole transaction which is desirable. Depending on the scenarios, we can also add different Logic Controllers like Loop Controllers, Random Controller, etc.
Creation or recording of HTTP Requests
When we perform an operation like clicking a button, several HTTP requests are sent to the server. While scripting we need to create all these requests, in order to determine the time taken for processing the requests.
One way of doing this is to add different HTTP requests and configure them with values like – URL, Port, request type(Get, Put, Post, Delete, etc), request body, request Header, etc. But this can get very cumbersome unless we are required to test very limited requests or need to test a particular HTTP request.
To perform this efficiently JMeter provides us an HTTP(s) Test Script Recorder, using which we can record scripts in JMeter directly by performing operations on a browser. Check our tutorial on recording scripts Record and Playback in JMeter.
Once we get hold of recording scripts, we can select a transaction controller like “Launch application” from the Target Controller of the HTTP(s) Test Script Recorder and perform the operations like launching the web application on the configured browser, the different HTTP requests will get added to the selected Controller.
We can add Timers between two transaction controllers to introduce think time like a timer with 3 seconds timeout value can be introduced between “Launch application” and “Search a Keyword” controllers to simulate the time a user takes to process the response and type a keyword to search.
In order to store and analyze the test results, we can different types of listeners studied in our tutorial – Listeners in JMeter.
Dry run the test
Before performing the test with an actual number of users we need to dry run the test with a very small number of users in order to validate the correctness of the script.
Configure and schedule the load test
Once the scripts are verified, we will configure the load test with the desired number of users and schedule the load test.
Run and analyze the test
Once the whole test script creation and configuration is done, we will run the test by clicking the play icon or pressing Ctrl+r on the keyboard. During the test execution, we will monitor the server in parallel. Once the test gets over, we can store and analyze the test results.
Now we have seen a basic test plan for a web application, still, there are a couple of things which needs to be taken care of-
- During testing, we should not hard code the values like – search terms and user credentials, etc. For this, we need to parameterize the test scripts. To learn the parameterization concept, check our tutorial – Parameterization in JMeter.
- Creating dynamic scripts and handling session variables is another thing that needs to be considered while scripting. For handling these issues we have a concept of correlation, check our tutorial – Correlation in JMeter for learning the same.
That’s all we have in this section, please share it with your friends and colleagues. Check out the complete JMeter tutorial below.