// Tutorial //

How To Use JMeter To Record Test Scenarios

Published on July 1, 2014
Default avatar
By Mitchell Anicas
Developer and author at DigitalOcean.
How To Use JMeter To Record Test Scenarios

Introduction

In this tutorial, we will teach you how to set up and use the Apache JMeter HTTP(S) Test Script Recorder to record HTTP requests. Recording HTTP requests is a great way to building test plans, and can be useful in creating tests that closely mimic a normal user’s behavior.

This tutorial assumes that you have a basic knowledge of Apache JMeter. If you are new to JMeter, here is another tutorial that can get you started: How To Use Apache JMeter To Perform Load Testing on a Web Server

Prerequisites

Here is a list of the software that this tutorial requires:

For reference, when writing this tutorial, we used the following software versions:

  • Oracle Java 7 update 60, 64-bit
  • JMeter 2.11
  • Firefox 30.0

Start Building a Test Plan

First, start JMeter. Then let’s start building a test plan. If you already have a test plan that you would like to start with, skip this section and move on to adding a Recording Controller to your Thread Group (the next section).

Minimally, we will want to add a Thread Group and HTTP Request Defaults. Let’s get start by adding a Thread Group.

Add a Thread Group

Add a Thread Group to Test Plan:

  1. Right-click on Test Plan
  2. Mouse over Add >
  3. Mouse over Threads (Users) >
  4. Click on Thread Group

Set the Thread Group properties with the following values:

  • Number of Threads (users): Set this to 50
  • Ramp-Up Period (in seconds): Set this to 10.
  • Loop Count: Leave this set to 1.

Thread Group Properties

Add an HTTP Request Defaults

Now let’s add HTTP Request Defaults to Thread Group:

  1. Select Thread Group, then right-click it
  2. Mouse over Add >
  3. Mouse over Config Element >
  4. Click on HTTP Request Defaults

In HTTP Request Defaults, under the Web Server section, fill in the Server Name or IP field with the name or IP address of the web server you want to test.

HTTP Request Defaults

If your web server uses cookies, you can add support for cookies by adding an HTTP Cookie Manager to the Thread Group:

  1. Select Thread Group, then right-click it
  2. Mouse over Add >
  3. Mouse over Config Element >
  4. Click on HTTP Cookie Manager

Add a Recording Controller

Now let’s add a Recording Controller to Thread Group:

  1. Select Thread Group, then right-click it
  2. Mouse over Add >
  3. Mouse over Logic Controller >
  4. Click on Recording Controller

The Recording Controller is where recorded HTTP Request samplers will be created. The next step is to set up an HTTP(S) Test Script Recorder.

Add HTTP(S) Test Script Recorder

Now let’s add an HTTP(S) Test Script Recorder to the WorkBench:

  1. Select WorkBench, then right-click it
  2. Mouse over Add >
  3. Mouse over Non-Test Elements >
  4. Click on HTTP(S) Test Script Recorder

Note: Items that are added to the WorkBench do not get saved with the rest of the test plan. If you want to save your WorkBench, right-click on WorkBench, then click Save Selection As…, and save it to your desired location. After it is saved, you may add it to any test plan that you have open by using the “Merge” menu item, and selecting your saved WorkBench.

Port Setting

The default port that the HTTP(S) Test Script Recorder proxy will run on is 8080. This can be changed by changing the Port setting under Global Settings.

Including or Excluding URL Patterns (Optional)

In the HTTP(S) Script Recorder, you may add URL Patterns, written as regular expressions, to include or exclude when you record. This can be useful to either include only the types of content you want to request (e.g. *.html, *.php, etc) or to exclude the types of content you do not want to request (e.g. *.jpg, *.png, *.js, etc).

To add a URL Pattern, click the “Add” button under the URL Patterns to Include or URL Patterns to Exclude section, then click on the top of the white area in the section. You should now be able to type in a pattern. Repeat the process to add more patterns.

Example: URL Patterns for webpages

.*\.html
.*\.php
.*\.htm

Example: URL Patterns for images

.*\.png
.*\.jpg
.*\.gif

Here is a screenshot of the URL Patterns to Exclude for excluding images:

URL Patterns to Exclude Images

Adding Items to the Script Recorder (Optional)

Adding JMeter items to a the HTTP(S) Test Script Recorder will make recorded requests inherit the added item. For example, if we add a Timer item to the Script Recorder, the Timer will be added to each HTTP Request that is recorded. When the test is run, the timer will cause each test thread to wait before performing the HTTP Request.

Let’s add a Constant Timer to HTTP(S) Test Script Recorder, as an example:

  1. Select HTTP(S) Test Script Recorder, then Right-click it
  2. Mouse over Add >
  3. Mouse over Timers >
  4. Click on Constant Timer

You may configure the thread delay to whatever you desire.

Constant Timer

Suppose that you want to simulate a user clicking on a different page every 2 seconds. Setting the thread delay to 2000 ms will accomplish this by adding a 2 second delay to each HTTP Request that is recorded.

This is just one example of how you can add items to the Script Recorder to help create a test plan that performs the tests that you desire.

Start Recording

Clicking on the “Start” button, on the bottom of the Script Recorder window, will start the JMeter proxy server which will be used to intercept and record browser requests. Click on the Start button (of the recorder) now.

The first time you attempt to run the recorder, it will display an error saying that it can’t start because a certificate does not exist. Click OK, then click Start a second time. You should see a message that says that a temporary certificate named ApacheJMeterTemporaryRootCA.crt has been created in JMeter bin directory. Click OK and continue.

Temporary Certificate Created

Note: If you browser already uses a proxy, then you need to configure JMeter to use that proxy before starting JMeter, using the command-line options -H and -P.

Configure Firefox To Use JMeter Proxy

We will use Firefox as our browser when using the JMeter HTTP(S) Test Script Recorder because, unlike Chrome and some other browsers, it does allows you to override system-wide configuration for its proxy settings.

Configure Firefox to use localhost (127.0.0.1) on port 8080 as its proxy for all traffic by following these steps:

  1. Open Firefox
  2. Go to the Preferences menu
  3. Click on the Advanced tab
  4. Then Network tab
  5. In the “Connection” section, click on “Settings…”
  6. Select the “Manual proxy configuration” radio button
  7. Set HTTP Proxy to “localhost” and Port to “8080”
  8. Check “Use this proxy server for all protocols”
  9. Click OK and exit the Preferences menu

Note: When Firefox is configured to use JMeter’s Script Recorder as a proxy, it will only work properly if the Script Recorder is running.

Recording HTTP Requests

Now that our test plan’s HTTP(S) Test Script Recorder is running, and Firefox is configured to use it as a proxy, the HTTP requests that Firefox sends will be recorded. Let’s test it out.

In Firefox, go to your server’s homepage (the same server that you configured in your JMeter HTTP Request Defaults):

http://your_domain.com/

Now there should be a little triangle next to your Recording Controller. Click on it to expand and show the requests that it has recorded. You should see the HTTP requests that were recorded, depending on which URL Patterns you have included and excluded. Feel free to browse your site to record more requests.

Here is an example of what was recorded when visiting the homepage of a WordPress site (with no URL Patterns set):

Recorded HTTP Requests

As you can see, a lot of requests were created. You may refine the list of HTTP requests by simply deleting unwanted entries here.

If you do not see any entries under your Recording Controller, you will want to review your URL Patterns in the HTTP(S) Test Script Recorder (Hint: Remove all includes and excludes to record everything).

Once you are done recording, click the “Stop” button at the bottom of the HTTP(S) Test Script Recorder window. Note that Firefox will no longer be able to reach any pages (because it is configured to use port 8080 as a proxy)–configure it to use “No proxy” if you want to function normally.

Run Your Test Plan

Once you are happy with the test plan you have recorded, save it, then run it. It will function exactly like a manually created test, so you can configure it, delete, and add items to make it match your desired test case more closely.

Conclusion

Now that you are able to use the HTTP(S) Test Script Recorder to assist the creation of JMeter test plans, you should have an easier time creating test plans that mimic realistic scenarios. Feel free to explore the recorded requests in your Recording Controller to learn more about the kinds of requests that are made when users browser your web server.

Good Luck!


Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up

Tutorial Series: Load Testing with Apache JMeter

Load testing your web application servers can be an important step in preparing your environment for production. Apache JMeter can be used to simulate the load of many users connecting to your servers, which can be useful in identifying your capacity limits and potential bottlenecks in your setup.

This series will show you how to use JMeter to record test scenarios, and to perform load testing on your web servers.

About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?
10 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

very well written and easy to use, thanks.

Hi, Mitchell. Great article, thanks.

Can you access any sites with FireFox when the recorder is not running? If so, FireFox is not configured properly.

If FireFox is configured correctly, try removing any URL Patterns from the include/exclude section.

My script is not recording anything. I am running my web application in local server. So, I changes the firefox network settings according to my port. Then, I set the port number in jmeter under the “HTTP(S) Test Script Recorder” also. and when I start the script recorder I tried the many events on the website but Jmeter doesn’t catch any request. Can you please help in identifying what & where I am going wrong?

very clear explanation.thank you

Hi, I followed the same steps for Recording using HTTP Script recorder After Configuring Firefox To Use JMeter Proxy, I am unable to record since I am getting following error in Firefox

“{The proxy server is refusing connections Firefox is configured to use a proxy server that is refusing connections. Check the proxy settings to make sure that they are correct. Contact your network administrator to make sure the proxy server is working.}”

I have done performance test of below page but i can see that everything is displaying as 0. Can somebody help me here. Which JMeter version shall i use ?

Thanks in advance.

Example url is here for which i performed test.:

http://pnrstatusirctc.in/irctc-registration-irctc-signup-process/

Thanks in advance.

This comment has been deleted

2016/02/25 19:10:26 WARN - jmeter.protocol.http.proxy.ProxyControl: Could not open/read key store C:\Users\abhishekver\Desktop\apache-jmeter-2.10\apache-jmeter-2.10\bin\proxyserver.jks (The system cannot find the file specified) 2016/02/25 19:10:26 INFO - jmeter.protocol.http.proxy.ProxyControl: Creating Proxy CA in C:\Users\abhishekver\Desktop\apache-jmeter-2.10\apache-jmeter-2.10\bin\proxyserver.jks 2016/02/25 19:10:26 ERROR - jmeter.protocol.http.proxy.ProxyControl: Could not initialise key store java.io.IOException: Cannot run program “keytool” (in directory “C:\Users\abhishekver\Desktop\apache-jmeter-2.10\apache-jmeter-2.10\bin”): CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(Unknown Source) at org.apache.jorphan.exec.SystemCommand.run(SystemCommand.java:142) at org.apache.jorphan.exec.SystemCommand.run(SystemCommand.java:125) at org.apache.jorphan.exec.KeyToolUtils.genkeypair(KeyToolUtils.java:123) at org.apache.jorphan.exec.KeyToolUtils.generateProxyCA(KeyToolUtils.java:181) at org.apache.jmeter.protocol.http.proxy.ProxyControl.initDynamicKeyStore(ProxyControl.java:1275) at org.apache.jmeter.protocol.http.proxy.ProxyControl.initKeyStore(ProxyControl.java:1205) at org.apache.jmeter.protocol.http.proxy.ProxyControl.startProxy(ProxyControl.java:431) at org.apache.jmeter.protocol.http.proxy.gui.ProxyControlGui.startProxy(ProxyControlGui.java:485) at org.apache.jmeter.protocol.http.proxy.gui.ProxyControlGui.actionPerformed(ProxyControlGui.java:370) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$400(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.awt.EventQueue$4.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.<init>(Unknown Source) at java.lang.ProcessImpl.start(Unknown Source) … 46 more