---
title: How to Record a Scenario with JMeter
url: https://blog.octoperf.com/how-to-record-a-scenario-with-jmeter/
date: '2018-04-26'
authors:
- jloisel
categories:
- JMeter
tags:
- Recording
- HTTP
- Proxy
- JMeter
description: Learn how to use the JMeter built-in http(s) recorder to record HTTP and HTTPS traffic directly from a web browser (like Firefox or Chrome).
---

# How to Record a Scenario with JMeter

So you started designing a scenario using [JMeter](https://jmeter.apache.org/) manually. After working a while on this grueling task, you start wondering: **Isn't there a way to record browser interactions with JMeter?**

The short answer is **yes**! [Jmeter's HTTP(s) Test Script Recorder](https://jmeter.apache.org/usermanual/component_reference.html#HTTP(S)_Test_Script_Recorder) is exactly designed to **record test scenarios**.

This tutorial teaches you:

- What a [Proxy](https://en.wikipedia.org/wiki/Proxy_server) is and **how the recorder works**,
- **How to intercept and record HTTP Requests** automatically while using your [web browser](https://en.wikipedia.org/wiki/Web_browser),
- How to record [SSL-secured](https://en.wikipedia.org/wiki/Transport_Layer_Security) (`https` requests),
- **How to configure Proxy Settings** with [Google Chrome](https://www.google.com/chrome/index.html) and [Firefox](https://www.mozilla.org/),
- And the most important part: **recording the script**!

You'll see **there are a few caveats** but everything is well explained.

We assume you already:

- Have **JMeter** installed (See for [Mac Setup](https://blog.octoperf.com/how-to-install-jmeter-on-a-mac/) and [Windows Setup](https://blog.octoperf.com/how-to-install-jmeter-on-windows/)),
- And know [How to use JMeter](https://blog.octoperf.com/jmeter-tutorial-for-beginners/).

I know *how impatient you are*, so **let's start now**!


## Recorder Setup

### How a Proxy works

![How Proxy Works](https://blog.octoperf.com/img/blog/jmeter-recording/how-proxy-work.png "Picture showing Proxy Principle")

Before we configure JMeter, let me briefly explain how the recording process works. A [Proxy](https://en.wikipedia.org/wiki/Proxy_server) is a component which **inserts between you and the remote server**. In some way, it's similar to a [Man-In-The-Middle Attack](https://en.wikipedia.org/wiki/Man-in-the-middle_attack), except you're **spying on yourself**!

As **anything** between the remote server and you **goes through the Proxy**, when *JMeter* acts like a Proxy, it can record all your browser interactions (given it's [http](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) or [https](https://en.wikipedia.org/wiki/HTTPS)).

**How can JMeter act like a Proxy**? By using [Jmeter's HTTP(s) Test Script Recorder](https://jmeter.apache.org/usermanual/component_reference.html#HTTP(S)_Test_Script_Recorder).


### JMeter Recorder Template

The easiest way to get started right away is to use the `Recorder Template`:

- Launch JMeter,
- Click on `Files > Templates...`,
- Select `Recorder` from *Select Template* dropdown,
- Then click on `Create`.

![JMeter Recording Template](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-recording-template.png "Templates panel accessible from `Files > Templates`")

Once you click on *Create*, JMeter creates a bunch of elements required to properly **record http and https traffic**. Let's examine the elements being created.

![JMeter Recording Test Elements](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-recording-test-elements.png "JMeter Recording Test Elements")

Your JMX project should now contain the following elements.

- [User Defined Variables](https://jmeter.apache.org/usermanual/component_reference.html#User_Defined_Variables): lets you define an initial set of variables, just as in the **Test Plan**,

![User Defined Variables](https://blog.octoperf.com/img/blog/jmeter-recording/user-defined-variables.png)

- [HTTP Request Defaults](https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request_Defaults): lets you set default values that your *HTTP Request* controllers use,

![HTTP Request Defaults](https://blog.octoperf.com/img/blog/jmeter-recording/http-request-defaults.png)

- [HTTP Cookies Manager](https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Cookie_Manager): stores and sends cookies just like a web browser,

![HTTP Cookies Manager](https://blog.octoperf.com/img/blog/jmeter-recording/http-cookies-manager.png)

- [Thread Group](https://jmeter.apache.org/usermanual/component_reference.html#Thread_Group) with a [Recording Controller](https://jmeter.apache.org/usermanual/component_reference.html#Recording_Controller) inside: it will contain the request being recorded by JMeter's proxy,

![Thread Group](https://blog.octoperf.com/img/blog/jmeter-recording/thread-group.png)

- And finally the [HTTP(S) Test Script Recorder](https://jmeter.apache.org/usermanual/component_reference.html#HTTP(S)_Test_Script_Recorder): controls JMeter's Proxy settings.

![Test Script Recorder](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-http-recorder.png)

A few [View Results Tree](https://blog.octoperf.com/jmeter-result-analysis-the-ultimate-guide/#view-results-tree) are located here and there **for debugging purpose**. 

### Test Script Recorder Settings

Let's now examine the **most interesting Script Recorder Settings**:

- **Global Settings**

  - **Port**: HTTP and HTTPS proxy port. The proxy will be running on this [TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) port, listening for http requests,
  - **HTTPS Domains**: List of domain (or host) names for HTTPS. Use this to **pre-generate certificates** for all servers you wish to record. Example: `httpbin.org`,

- **Test Plan Content**:

  - **Target Controller**: by default, everything is recorded within `Recording Controller`. But you can change it to whatever you want (like the `Thread Group` directly),
  - **Grouping**: groups http request by trying to determine which requests belong to the same page,
  - **Capture HTTP Headers**: creates [HTTP Headers Manager](https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Header_Manager) as http request child, capturing the headers sent by the web browser. **Leave checked** as most http headers are important,

- **HTTP Sampler Settings**:

  - **Use Keep-Alive**: enable [HTTP Keep-Alive](https://en.wikipedia.org/wiki/Keepalive#HTTP_keepalive) to signal that the connection should be kept open for further messages (by default for *HTTP 1.1*). **Most sites are HTTP 1.1 compliant** now,
  - **Follow Redirects**: generates only a single HTTP Request when multiple [HTTP redirections](https://en.wikipedia.org/wiki/URL_redirection) are detected, and enables *Follow Redirects* on it.

![JMeter Recorder Request Filtering](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-recorder-request-filtering.png "JMeter Recorder Request Filtering")

In addition to general settings, the recorder offers the ability to **filter requests**. How does it work? Based on *inclusion* and *exclusion* patterns, the **recorder chooses** if a request must be stored during the record or not.

**What are filters for**? Mostly for filtering out resources like images, [CSS Stylesheets](https://www.w3.org/TR/html401/present/styles.html) and/or [Javascript](https://www.w3schools.com/js/js_whereto.asp) files. But, **that's not mandatory**. In fact, **it may be less realistic** to filter those resources since they are part of the application anyway.

It's time to **record http requests** using JMeter's Proxy!

## HTTPS Setup

**Recording HTTPS websites requires a bit more work** than plain HTTP websites. Let's see why.

Let's start JMeter's Proxy Recorder:

- Select `HTTP(s) Test Script Recorder` within the tree on the left,
- Click on `Start` button: a dialog should show up asking to install [CA Root Certificate](https://en.wikipedia.org/wiki/Root_certificate). This certificate must be installed within the web browser to **support recording HTTPs traffic**.

![Root Certificate Dialog](https://blog.octoperf.com/img/blog/jmeter-recording/root-certificate-dialog.png "Root Certificate Dialog")

**It may look complex at first glance**, but don't worry. Let me explain why you see this.

### Root Certificate Authority

[TLS/SSL](https://en.wikipedia.org/wiki/Transport_Layer_Security) (The *S* in `HTTPS`) guarantees that there are **no spies between you and the server** you are contacting (no proxies). Normally, you use an `HTTP CONNECT` to open up a `TCP` connection through the *proxy*. In this case, the proxy will not be able to decrypt the traffic and **directly tunnel you** to the remote server.

If **you want the proxy to decrypt HTTPS Traffic**, you need to take the following approach:

- Client starts an `HTTPS` session,
- Proxy transparently intercepts the connection and returns a  generated (and weak) [SSL certificate](https://www.instantssl.com/ssl-certificate.html), signed by a CA ([Certificate Authority](https://en.wikipedia.org/wiki/Certificate_authority)) that is unconditionally trusted by the client, (we'll see how)
- Proxy starts an `HTTPS` session to target,
- Proxy verifies integrity of **SSL certificate**; failing if the certificate is invalid,
- Finally, Proxy streams content, decrypts it and re-encrypts it with intermediate certificate.

That's known as [MITM Attack](https://en.wikipedia.org/wiki/Man-in-the-middle_attack).

![MITM Attack](https://blog.octoperf.com/img/blog/jmeter-recording/mitm-attack.jpg "JMeter's Proxy is based on Man-In-The-Middle Attack to decrypt HTTPS Traffic")

Said otherwise, we need to **install and trust JMeter's Root Certificate** to allow JMeter's Proxy **to decrypt HTTPS traffic**. Trust me, there is no risk unless you leak the Root certificate to a malicious third party.

![JMeter's Certificate Authority](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-root-certificate.png "JMeter's SSL Certificate Authority")

JMeter generates a *Root Certificate Authority* within the `<JMETER_HOME>/bin` folder. You should find a file named `ApacheJMeterTemporaryRootCA.crt` in this folder. Let's see **how to install it in common web browsers**.

### Root CA Validity

By default, JMeter generates a `Root CA valid only 7 days`. **That's annoying** since we need to redo the procedures below every week. But, there is a way to hack this.

Open `<JMETER_HOME>/bin/jmeter.properties` and locate the following lines:

```
# The default validity for certificates created by JMeter
#proxy.cert.validity=7
```

For example, to have certificates valid for a year, change it to:

```
# The default validity for certificates created by JMeter
proxy.cert.validity=365
```

Remember to:

- Stop JMeter,
- Change the `jmeter.properties`, 
- Delete any existing `<JMETER_HOME> / bin / ApacheJMeterTemporaryRootCA.crt`,
- And restart JMeter.

That should save you from repeating the **browser installation procedures** below too often.

### Firefox Setup

To install JMeter's *Trusted Root Certificate Authority* in **Firefox**:

- Open Firefox,

![Firefox Menu](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-menu.png)

- Open main menu and select `Preferences`,

![Firefox Prefs Menu](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-prefs-menu.png)

- Select `Privacy & Security` settings and scroll-down to the bottom of the page,

![Firefox Privacy Settings](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-privacy-settings.png)

- Click on `View Certificates` then click on `Import`,

![Firefox Certificates](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-certificates.png)

- Select the `ApacheJMeterTemporaryRootCA.crt` located in `<JMETER_HOME>/bin` folder. (`<JMETER_HOME>` is where JMeter is installed),

![Firefox Trust Certificate](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-trust-certificate.png)

- You should see the certificate within the *Certificate Manager*.

![JMeter Root CA Installed in Firefox](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-certificate-installed.png)

That's it! It should take you only a few minutes to install it.

### Google Chrome Setup

Let's see now how to install JMeter's *Trusted Root Certificate Authority* in **Google Chrome**:

- Open Google Chrome,
- Click on main `menu`,

![Chrome Menu](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-menu.png)

- Then click on `Settings`,

![Chrome Menu](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-settings-menu.png)

- In the search field, enter `privacy` and scroll down to `Manage Certificates`,

![Chrome Privacy Settings](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-privacy-settings.png)

- Click on `Authorities`, then click on `Import`,
- Select the `ApacheJMeterTemporaryRootCA.crt` located in `<JMETER_HOME>/bin` folder. (`<JMETER_HOME>` is where JMeter is installed),

![Chrome Import Authorities](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-import-authorities.png)

- Check `Trust this certificate for identifying websites`,

![Chrome Trust Certificate](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-trust-certificate.png)

- Finally, you should see JMeter's Root Certificate Authority installed.

![Chrome Certificate Install](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-certificate-installed.png)

That required quite a bit of work to compile! But we have **fully working HTTPS Recording** in both web browsers.

Now, we're ready to **configure those browsers with JMeter's Proxy settings**.

## Proxy Setup

### Firefox Setup

To configure JMeter's *Proxy* in **Firefox**:

- Open Firefox,

![Firefox Menu](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-menu.png)

- Open main menu and select `Preferences`,

![Firefox Prefs Menu](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-prefs-menu.png)

- Select `General` section, then scroll-down to `Network Proxy`,

![Firefox General Menu](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-proxy-settings.png)

- Finally enter both *http* and *https* proxies with hostname `localhost` and port `8888` (default proxy port).

![Firefox Proxy Settings](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-proxy-settings-set.png)

- Click on `OK`.

Firefox is now configured with JMeter's proxy settings and ready to record `http` and `https` requests.

### Google Chrome Setup

To configure JMeter's *Proxy* in **Google Chrome**:

- Open Google Chrome,
- Click on main `menu`,

![Chrome Menu](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-menu.png)

- Then click on `Settings`,

![Chrome Menu](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-settings-menu.png)

- Enter `proxy` and select `Open Proxy Settings`. It should open system wide proxy settings. (depends on operating system)

![Chrome Menu](https://blog.octoperf.com/img/blog/jmeter-recording/chrome-proxy-settings.png)

- Finally enter both *http* and *https* proxies with hostname `localhost` and port `8888` (default proxy port).

Just beware that setting system wide proxy settings affects all applications sensitive to those settings (not just web browsers).

## Recording The Scenario

We're finally reaching the most entertaining part of the tutorial: **recording the script**! If you're still there (and I won't mind if you're already sleeping), let's try to record [HTTPBin](https://httpbin.org).

![JMeter Start Recording](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-start-recording.png)

Click on the `Start` button within the *HTTP(S) Test Script Recorder* to start JMeter's proxy. Click on `OK` when the Root CA dialog appears as see previously. In this example, we'll use *Firefox* because its proxy settings are confined.

![Firefox Proxy Issue](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-proxy-issue.png)

If you ever see the message `The proxy is refusing connections` within Firefox, please check:

- You have started the *HTTP(S) Test Script Recorder* by clicking on `Start` button,
- That proxy settings are properly set to the appropriate `hostname` and `port`.

It usually boils down to the points described above. 

![Firefox HTTPBin](https://blog.octoperf.com/img/blog/jmeter-recording/firefox-httpbin.png)

Now browse to [https://httpbin.io](https://httpbin.io/). You should see requests filling in within the **Recording Controller**.

![JMeter HTTPBin Recording](https://blog.octoperf.com/img/blog/jmeter-recording/jmeter-httpbin-recording.png)

Congratulations! You've just **recorded an SSL protected website using JMeter**. Once you are finished, go back to JMeter's Recorder, and click on `Stop` to stop the recording. Remember **proxy settings are still set within Firefox**. Any attempt to browse while JMeter's proxy is stopped / not running will result in the `The proxy is refusing connections` error.

## Additional resources

In case you find JMeter recording too cumbersome, you may want to use the [HAR import feature of OctoPerf to get there](https://blog.octoperf.com/jmeter-vs-octoperf/).
It's available even with a free account and you can export your script back as a JMX anytime.

After recording it's also time to **rework the recorded script** like explained in our [JMeter REST API Testing](https://blog.octoperf.com/rest-api-testing-with-jmeter-step-by-step-guide/) guide:

- Handling dynamic parameters,
- making the script more realistic and random,
- etc.

You're **new to JMeter**? No worries. We have cooked a [JMeter Tutorial](https://blog.octoperf.com/jmeter-tutorial-for-beginners/) for beginners too.
