JMeter's Superpower: The HTTP Proxy Server

Posted by Dzmitry Kashlach

JMeter has a major superpower: the ability to record traffic in a single bound (or, in non super hero speak, as it happens).

This feature allows testers to avoid the long and tedious task of manually recording traffic and simply automates the task. The HTTP Proxy Server is the tool the superpower operates through, much like Wonder Woman's magic lasso ;).

 

The Proxy Server allows JMeter to watch and record actions while users browse web application with standard browsers. JMeter will create test sample objects and store them directly into the test plan as the user browses (so samples can be interactively viewed in real time).

How does the magic lasso of the HTTP Proxy Server work?

Create a new test-plan and switch to WorkBench. Then go to “WorkBench”->”Add”->”Non-Test Elements”->”HTTP Proxy server”. 

JMeter HTTP Proxy Server

The first thing we have to do is set up the browser for traffic recording. 

Specify the free port that can be used for the proxy. This port should not be occupied with another server. Our tester used a WAMP server with the testing application installed on the PC, so we changed the default port 8080 to 8090. Then open your browser network settings (We used Mozilla Firefox).

Connection Settings

Set “Manual proxy configuration” and specify 127.0.0.1 for the HTTP Proxy, because the HTTP Proxy server will work on the local host. Do not forget to set the same port as in proxy server settings, e.g. 8090. Next, add the recording controller for collecting HTTP requests.
The Recording Controller is a placeholder indicating where the proxy server should record samples to.

During the test run, it has no effect. But during the recording, use the HTTP Proxy Server and all recorded samples will be saved by default under the Recording Controller.

Recording Controller
Set up patterns of traffic recording.  You know, that typical web page that consists not only of dynamic PHP or JavaScript or whatever else but, also has static content such as pictures or icons.  If you prefer to work exclusively with dynamic pages, then filter unwanted traffic either during recording or manually during debugging. Super easy to do during recording.


Note that the table forms URL Patterns to exclude. If you leave this form empty, all incoming traffic will be recorded and placed into the Recording Controller. But if you specify patterns for target URLs, then the HTTP Proxy Server will filter URLs that match the pattern.
Alternate option if the preference is that the HTTP Proxy Server record only requests to *.php pages of the testing web-application. In this scenario, set “.*\.(jpg|png|gif)” for excluded patterns. Then note “Capture HTTP Request Headers”. If left unchecked, JMeter will record headers of HTTP requests from the browser. They can be very useful while testing applications with high requirements to security and in other specific cases. It’s better to leave it checked.

Now JMeter's HTTP Proxy Server is ready. 

Add the HTTP Request Defaults to the Thread Group. Specify the Server IP=”localhost” and port = 8090. These parameters will be removed from HTTP Requests during recording to avoid duplication.

To record a more realistic test plan, insert timers between requests.

This will allow the recording of the thinktime of the user. For this purpose add a Constant Timer to the HTTP Proxy Server node to record think-time (right-click on the “HTTP Proxy Server” node and choose “Add,” “Timer,” and then “Constant Timer.”).  After that action change the “Thread Delay” on the timer to “${T}”. This will tell the proxy server to record your time rather than add a constant time for each request.
Note that a timer causes the affected samplers to be delayed. That is, the affected sampling requests are not sent before the specified delay time has passed since the last received response. Therefore, you should manually remove the first sampler's generated timer since the first sampler usually does not need one.

Finally, the test plan should look like test plan below.

JMeter Test Plan
We are ready to record. Let’s start the proxy and surf through the testing application.
See what you get after the recording is displayed below

Note, the HTTP Proxy has recorded only the request to *.php pages according to filtering rule.

The timer recorded the user think time. Now the testing scenario will repeat user actions precisely.

Use this power wisely. With magic lassos, comes great responsibility.

Watch and Join

Watch a recap of the first JMeter Meetup "Load testing with JMeter - Best practices, regular expression extraction and use." (Meet up date-Wednesday, May 9, 2012, Santa Clara, CA.)

To join our meetup groups:

JMeter Meetup 
J
Meter NYC
T
he Apache JMeter London Group