Maybe you are new to load testing and don’t know where to get started. Fortunately for you, we will introduce you to JMeter’s HTTP Proxy Recording tool, which is a great option for creating load tests quickly with minimal effort.
What the JMeter HTTP Proxy Recording Tool is
The JMeter HTTP Proxy Recording Tool can help you create a test script while you are interacting with your application. The HTTP proxy works locally to capture all of the traffic you generate from accessing your application and create the necessary steps in JMeter to replay this same traffic pattern. This will work to capture both the outbound traffic.
When to Use the JMeter HTTP Proxy Recording Tool
This tool is powerful for creating a quick script that can get you up and running, it can’t replace a well written script with human intelligence. Oftentimes, your recording will break soon after creation due to changing CSRF tokens, JSession ID’s, or other dynamic content. Keep this in mind so you are aware your job may just be beginning once your recording has completed.
Here are some situations where you can use this time saving tool:
- When investigating how an application works before writing a script
- To create a base script to be edited/improved
- When time is limited and a script is needed quickly
- When learning JMeter and how to create more advanced scripts
Getting Started with the JMeter HTTP Proxy Recording Tool
First things first, you will need to download JMeter if you haven’t. The latest version of JMeter, 5.0, is available for download. Version 5.0 includes some great new updates to the recorder, which we have documented in detail here.
5 Quick Tips for JMeter HTTP Proxy Recording
JMeter 5.0 has the embedded HTTP Proxy recording tool that can be used for Web and Mobile HTTP(S) traffic recorder. Getting started is easy if you follow these quick tips to get going:
1. Use a recording template
JMeter provides a great recording template that can be easily deployed, by clicking on File -> Templates.
Select Recording from the drop down and click on Create. There is good documentation in the links shown when selecting the template, which provide a step by step tutorial
This test plan can be used as is without modifying values, providing everything needed for a good recording by default. A good practice is to keep a backup of the original recording by saving frequently. If you do end up making a mistake, JMeter keeps its own version history in the Backup folder.
2. Make sure you record what matters (and only what matters)
If you already know the domain that your application runs on, it’s highly recommended to set it as Inclusion domain. When setting an inclusion rule, anything outside this specified domain will be Excluded to avoid capturing irrelevant information. This feature can especially help to avoid recording any Telemetry calls from browser or mobile.
To set up your inclusion rule, go to the HTTP(S) Test Script Recorder and click on the tab Requests Filtering.
Urls pattern to include: .*your.domain.*
Urls pattern to exclude: .*
If you’d like to create complex patterns, you can use regular expressions. One in particular is shown in the screenshot below, and that helps us avoid recording embedded resources like fonts, styles and images (basically exclude file extensions like bmp,gif,jpg,png,ttf,woff,css and js). We recommend using this pattern to keep our script simple. Later you can set up in the advanced settings of the sampler to retrieve all the embedded resources if they are required.
3. Use updated certificates for recording HTTPS traffic
HTTPS testing is a more complicated process than HTTP testing, and requires the creation of temporary certificates to test it. JMeter generates certificates for 7 days validity by default. It’s a good practice to leave the expiration as is.
To generate the file, you click on Start button and the file ApacheJMeterTemporaryRootCA.crt is generated in the Bin folder. This file needs to be installed in your browser or mobile device if you are going to record HTTPS traffic, otherwise HTTPS traffic will be ignored.
To install this certificate in the most common browsers, please do the following:
Preferences -> Privacy and Security -> View Certificates -> Authorities -> Import and check all trust boxes.
- Chrome or Opera
Double click the crt file, select system keychain and add.
Share the .crt file to the iPhone either via email or a file share app. Once in your mobile, open it and install. Make sure it’s enabled: Settings -> General -> About -> Certificate Trust Settings
For version below 7, Share the .crt file to the device either via email or a file share app. Once in your mobile, open it and instal. Make sure it’s enabled: Settings -> Security -> Trusted Credentials -> User
For Android version 7 or above, take a look into this link for specific considerations.
Once you have properly installed the certificate file, you need to redirect the traffic to the proxy recorder. The recorder is located in localhost or 127.0.0.1 at the port 8888 by default for browsers, for mobile devices you need to update manually the proxy server in the Wi-fi settings with the IP address and ports where the recorder is located.
4. Use a prefix for HTTP Sampler Settings
We recommend the Prefix option from HTTP Sampler Settings, because it’s easier to identify the requests that belong to certain transaction. Additionally, this preserves the path’s name in the label, which also help when doing the scripting, debugging and correlation.
Once you finish the recording, don’t forget to sort the numeric order of the samplers. By defaults, the samplers are ordered is by the response time. To get the order to match the numbering that was given before sampling, we need to sort them.
You may notice some lapse in the samplers, which is most likely due to the Exclude pattern ignoring some of the requests to be recorded.
5. Practice before recording
Before you record your final script, make sure you practice the critical business flow you want to record 2 or 3 times first. When walking through the scenario, make sure you use random test data, execute it at the pace a regular user would, and remember to select carefully the keywords to be used for assertion, so they have less chance to break down the road.
The JMeter HTTP Proxy Recorder promises simplicity and easy test creation, but there are certainly some pitfalls that you need to be aware of first. We recommend that you follow the aforementioned 5 tips to create the most robust and realistic test possible with JMeter. Creating a suboptimal recording can have some negative consequences for your testing objectives, including poor test coverage, ongoing maintenance and potentially frequent re-recording of the script to keep up with application changes.