13 Jan 2015

Create a Web Test Plan Using JMeter

In JMeter a test plan describes a series of steps it will execute. A complete test plan will consist of one or more Thread Groups, logic controllers, sample generating controllers, listeners, timers, assertions, and configuration elements.

In this section, you will learn how to create a basic Test Plan to test a web site.

Add Thread Group Element (Adding Users)

Adding Thread Group element is the first step you want to do with every JMeter Test Plan. The Thread Group tells JMeter the number of users you want to simulate, how often the users should send requests, and the how many requests they should send.

To add this element:
  1. Open GUI mode of JMeter.
  2. Select Test Plan and Right-Click on it to get Add menu.
  3. Then select Add > Threads (Users) > ThreadGroup.
Now we can see the Thread Group element under Test Plan. If you do not see the element, then "expand" the Test Plan tree by clicking on the Test Plan element. You can rename the Thread Group by providing more descriptive name as needed.

Select the Thread Group element in the tree to see the Thread Group Control Panel in the right section of the JMeter window as shown in fig below.

Thread Group with Default Values

Next, you need to modify the default properties. The various characteristics of the threads (users) can be defined in thread group section as:
  1. Numbers of Threads (users)
  2. Ramp-up Period (when to send request), and
  3. Loop Count (how many times to repeat the request)
Based on above three properties of thread the load will be computed as:
Load = [ Number of Users ] x [ Ramp Up in Seconds ] x [ Loop Count ]

In our tutorial, increase the number of users to 5. In the Ramp-Up Period, leave the the default value of 1 seconds. This property tells JMeter how long to delay between starting each user. For example, if you enter a Ramp-Up Period of 5 seconds, JMeter will finish starting all of your users by the end of the 5 seconds. So, if we have 5 users and a 5 second Ramp-Up Period, then the delay between starting users would be 1 second (5 users / 5 seconds = 1 user per second). If you set the value to 0, then JMeter will immediately start all of your users. Finally enter a value of 2 in the Loop Count field. This property tells JMeter how many times to repeat your test. If you enter a loop count value of 1, then JMeter will run your test only once. To have JMeter repeatedly run your Test Plan, select the Forever checkbox.

Thus, 5 users ramping up one by one in an interval of 1 second each and repeat the request for 2 times.
So totally 5 x 1 x 2 = 10 users as a whole.

Add HTTP Request Defaults

Adding HTTP Request Defaults is nothing but defining the tasks that users will be performing. This element does not tell JMeter to send an HTTP request. It simply defines the default values that the HTTP Request elements use. We can add this element as:

Right-click on ThreadGroup element > Add > Config Element > HTTP Request Defaults.

The name of web site or web application that you want to test is to be inputted into the Server Name or IP field and leave the remaining fields with their default values. For the test plan you are building if we specify domain name as www.javakart.com then all HTTP requests will be sent to the same web server, www.javakart.com. Select this element to view its control panel as shown in fig.

HTTP Defaults for Test Plan

Adding HTTP Requests

The number of web pages to be tested, the number of HTTP requests should be created.Consider in our test plan we will make two HTTP requests to test two web pages. The first one is for javakart's home page (www.javakart.com/) and second one is for javakart's contact page (www.javakart.com/contact).

HTTP Request-1

Add first HTTP Request to JMeter Users (Thread Group) element as:

Go to Add > Sampler > HTTP Request.

After adding HTTP Request element select it and edit the following properties.
  1. Change the name of HTTP Request as 'Home Page'
  2. Set the path filed to ' / '

    HTTP Request for www.javakart.com Home Page
Note: There's no need to set server name field as we have already specified this value in HTTP Request Defaults element.

HTTP Request-2

Add second HTTP Request to JMeter Users (Thread Group) element. After adding HTTP Request element select it and edit the following properties.
  1. Change the name of HTTP Request as 'Contact Page'.
  2. Set the path filed to '/Contact'

    HTTP Request for www.javakart.com Contact Page
Note: There's no need to set server name field as we have already specified this value in HTTP Request Defaults element.

Add a Listener to View Test Results

A Listener, is a final element we need to add to our Test Plan that is responsible for storing all of our HTTP Requests in a file and presenting a Visual Model of data.

Select JMeter ThreadGroup element and add a listener as:
Add > Listener > Graph Results

After adding listener we need to specify a directory and file name of the output file. Now everything is done to run to a simple web test plan using JMeter.

Running Our Test Plan

To run our plan press Control + r or choose start from Run menu item. If "Start" is disabled, and "Stop" is enabled, then JMeter is running our test plan. Now click on Graph Results listener element to view the test results.





Popular Posts

Write to Us
Name
Email
Message