Load Testing of GUI using JMeter

What is JMeter?

JMeter is a Java based Open Source application which may be used for load/traffic testing of Web Applications. Following is the quote from the JMeter home page:

Apache JMeter may be used to test performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more). It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types. You can use it to make a graphical analysis of performance or to test your server/script/object behavior under heavy concurrent load.

What am I trying to do with JMeter?

I have used JMeter to do load testing of GUI. I wanted to record some regular transaction done in the GUI, like login, browse to different pages, display data (i.e search data from the DB), modify data and finally log out. Once this test case is recorded, then simulate a scenario where multiple users would do the same set of transactions simultaneously. My target was to find out the maximum number possible simultaneous sessions in my GUI.

How does JMeter do this?

  1. Initially JMeter needs to be configured to sit between the browser and the target server (on which GUI is running) and then it records all the HTTP requests sent by the browser to the server. If the target GUI accepts only HTTPS requests, then at this phase the browser should send HTTP requests (and NOT HTTPS) to the JMeter, JMeter records those requests and finally encrypt and send those to the server. Reverse thing happens for HTTPS response – JMeter receives the responses from the server, decrypts those, records and sends the HTTP responses back to the browser. The logical entity that is responsible for this HTTP message recording is called Http Proxy manager (described later).
  2. Once the recording is done, JMeter can be configured to start a large number of simultaneous threads – each thread represents one user sending/receiving the same set of requests/responses recorded in the first step. Now onwards, it’s between the JMeter and the server; browser is no longer used. Not surprisingly, JMeter maintains separate Http sessions for each user. The component responsible for this is called thread group.
  3. The result can be checked by using something called “listeners” – there are different flavors for the same.

How to use JMeter?

  1. Download JMeter from the here. 
  2. In case the server accessed and the desktop on which JMeter is launched reside in the same network run jmeter.bat from $JMETER_DIR/bin or just type “jmeter” in the command prompt.
  3. If a proxy sits in between the JMeter and the server, issue the following command from the command prompt:
jmeter -H <my.proxy.server> -P <port> -u <username> -a <password>
  1. Add a Thread Group to the Test Plan by right-clicking on Test Plan and Add -> Thread Group. Number of threads indicates the number of users to be simulated. Ramp up period is the time over which all the sessions will start uniformly one by one.
  2. Add the HTTP Cookie Manager to enable session tracking by right-clicking anywhere in the Test Plan hierarchy. Add -> Config Element -> HTTP Cookie Manager. Set the cookie policy to compatibility.
  3. Select the thread group. Right click “add -> Config element -> Http Request Defaults”. Set the Server name or IP to server’s IP. Keep pot number/path empty. Set Protocol to HTTP.
  4. Add a Recording Controller to the Thread Group by right-clicking on Thread Group -> Add -> Logic Controller -> Recording Controller. Rename the Recording Controller to take a suitable value. All the Http Requests recorded would be saved under this recording controller.
  5. Select workbench. Right click on workbench and add the Http proxy Server: add -> non-test elements -> Http Proxy Server. Port field – Enter “9090” (Any other value would do). Go to Target Controller – click on the drop down and select the recording controller created in step 6. As mentioned earlier, Http Proxy Server is the element which would record the Http requests and 9090 is the port on which the JMeter recording controller would run.
  6. In the same window, click on the Attempt Http Spoofing. It ensures that while recording the test case, JMeter encrypts the HTTP request before sending to the server and decrypts the HTTP response after receiving it back from the same.
  7. Add the following to the URL patterns to exclude:
  1. Add Gaussian Random Timer under Http Proxy Server. Right click on the Http Proxy Server, add -> Timer -> Gaussian Random Timer. Put the following values:
    1. Deviation (in milliseconds) -> 500.0
    2. Constant Delay Offset (in milliseconds) -> {$T}
  2. Gaussian random timer should be used if you want JMeter to record the time taken by the human user between clicking different links across the GUI. While executing the test case, the HTTP requests would be sent one after another maintaining the same time gap (as taken by the user). If Gaussian random timer is not used, all the requests would be pumped to the server at once. I am sure that no body wants to test such an unrealistic scenario.
  3. Add Listeners to the Thread Group by right-clicking on Thread Group -> Add -> Listener -> View Results in Table & View Results Tree & Aggregate Report. Different Listeners would represent the result (request sent, response received, time stamp, success/failure rate etc) in different form helping you to analyze.
  4. Go back to the Http Proxy Server. Now we are ready to record the test cases. So, click on Start button.
  5. Open the browser and configure proxy settings to point to JMeter’s proxy server. For Internet Explorer, click on Tools and select Internet Options, click on the Connections tab, click on LAN Settings, check the ‘Use proxy server for LAN… ‘ and set the address to ‘localhost’ and port to ‘9090’ (i.e. the port at which JMeter is configured to run). Now the browser will send the requests to the JMeter which in turn will send it to the server. JMeter will record them in between.
  6. Go to I.E. In the address bar type the following: http://Test_Machine_IP/Link
    Note, even if the server supports only secured connection, we are not using “https” here. Since, JMeter has already been configured to do https spoofing, browser will send normal http request to Jmeter and Jmeter will do further encryption before sending the requests to the server.
  7. Login to the GUI normally. And do some operations. Navigate through, perform actions etc as per your use case.
  8. Click on the Stop button from the Proxy Server once the recording is finished. All the requests will be stored under the recording controller. If the HTTP requests are not visible there, you must have missed something in the previous steps. Have a look. Fix it and then come back.
  9. Finally, run the test case by hitting Ctrl+R. A green box on the upper right corner should be visible indicating the test is running. The figure beside that green field indicates the number of threads (simulated users running at any instance of time). Different listeners will give detailed information about the test case while it is running. The box will turn gray once the execution stops.  Go back to the listeners to find the results.

Trouble shooting:

  1. If you find that requests are failing with some errors and if you are not sure whether the requests are really reaching the server or not, you should take a look of the access.log (For apache tomcat, the location of this log is configurable). access.log captures all the requests reaching the server and the corresponding HTTP response code.
  2. If you are encountering with “java.net.BindException: Address already in use: connect”, problem may be with Windows Operating System. You need to increase the number of ports the OS is using for establishing outbound TCP/IP connections.To fix it, Run regedit. Go to: “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\ Parameters”. Click on the Parameters. Create a new DWORD value with name MaxUserPort, Value Data -> 65534, Base -> Decimal. Then restart the system.

Further Reading:

  1. Official JMeter User’s Manual
  2. JMeter Proxy Step By Step

9 thoughts on “Load Testing of GUI using JMeter

  1. This is really a very helpful article… Thanks a lot… I hear that currently JMeter supports HTTPS without the spoofing… Have you tried it? Just asking

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s