In this tip we will take a look at recording performance tests using JMeter. In a previous tip on Running your first load test with JMeter, we looked at manually adding a Sampler for Yahoo Search. However, you may find that for more complicated test scenarios, you'll want the ability to record tests. This will help you save time when creating Samplers for your test plans. One easy way is to create multiple Samplers and record with them simultaneously.
Setting up a JMeter proxy
If you're not familiar with setting up a proxy, a quick explanation might be in order. A proxy simply acts as an intermediary for client requests to the various servers from which you've requested resources. By setting up a JMeter proxy, you're allowing JMeter to record the requests made and use the information derived to create a test plan.
If you're following along with this example, you'll want to start with a new test plan. To do this, add a proxy by right-clicking on WorkBench. Next click Add -> Non-Test Elements -> HTTP Proxy Server (as shown in figure 1 below).
Once the HTTP Proxy Server is added, select it in the left navigation tree, change the port from "8080" to "9090" and ensure the checkbox labeled "Retrieve All Embedded Resources from the HTML Files" is checked. Your settings should look similar to those shown in figure 2 below.
Next you'll need to set up your browser to point to a proxy server. For FireFox, you can find these settings by opening Preferences, selecting the Advanced icon, then the Network tab, and clicking the "Settings…" button. This should open a proxy configuration screen similar to the one shown in figure 3 below.
Select the "Manual proxy configuration" radio button and enter an HTTP Proxy of localhost on
port 9090. When finished, click OK and close FireFox preferences.
Recording information using the proxy
You should now be set up to record a test using JMeter. To start recording your tests, you'll want to start the JMeter proxy. To do this, navigate to the HTTP Proxy Server in JMeter and click the Start button at the bottom of the screen. This will start up the server.
At this point, JMeter will record anything you do in the browser you configured. Sometimes it's helpful to have two browsers opened. I'll often record tests using FireFox, and then also have an Internet Explorer or Safari browser open on the side so I can look stuff up without recording the transactions in JMeter.
For this tip's example, we'll be testing Yahoo Search. Open a FireFox browser and navigate to http://search.yahoo.com/. Once that page loads, search for "software testing." When the search results are returned, navigate back to JMeter and take a look at what's been recorded. As shown in figure 4 below, you should see a number of recorded Samplers under the WorkBench.
This should be enough for our example, so let's stop the proxy server. To do this, navigate to the HTTP Proxy Server in JMeter and click the Stop button at the bottom of the screen. You're no longer recording. If you're completely done, you'll also want to reset the proxy settings in your browser back to what they were before you set them to the manual configuration.
Making sense of what was recorded
After that, you'll see a number of "gossip-us-sayt" requests. The purposes of those requests might not be immediately obvious, but if you dig in just a bit by selecting one of them, you'll see that the server name these requests go to is " sugg.us.search.yahoo.net". That's the server that provides the spelling suggestions while you're typing (as shown below in figure 5).
At this point, you can move each of these elements from the WorkBench into your Test Plan. You can take all the Samplers recorded or you can select individual Samplers to move up. This allows you to record a series of Samplers, and then mix and match them as needed to create custom scenarios.
As a quick example, add a Thread Group to your test plan and move the first six recorded Samplers up under that Thread Group. Once those have been added, add a View Results Tree Listener as well (as shown in figure 6).
You can now run this test. If you do so (just run one thread for one loop), you'll see six responses come back successfully in the View Results Tree Listener. If navigate those results and look at the response data, you should find the content required to load the Yahoo Search page. The easiest example to recognize is the png file in the third result set shown in figure 7 below.
At this point, you can now customize those Samplers as needed to create the test scenarios
necessary to generate your target load.
This was first published in November 2009