Recording using HTTP Proxy in Jmeter

Configuring a proxy in Jmeter:

The first step before recording a script let’s configure a proxy in WorkBench.

WorkBench: The WorkBench simply provides a place to temporarily store test elements while not in use, for copy/paste purposes, or any other purpose you desire. When you save your test plan, WorkBench items are not saved with it. Your WorkBench can be saved independently if you like.

The HTTP(S) proxy server (prior to Version 2.10) or HTTP(S) Test Script Recorder (Version 2.10 onwards) allows JMeter to intercept and record your actions while you browse your web application with your normal browser. JMeter will create a test sample objects and stores them directly into your test plan as you go.

The recorder is implemented as an HTTP(S) proxy server. You need to set up your browser use the proxy for all HTTP and HTTPS requests. [Do not use JMeter as the proxy for any other request types - FTP, etc. - as JMeter cannot handle them.]

Launch Jmeter.
To use the recorder, add the HTTP(S) Test Script Recorder element to the workbench. Select the WorkBench element in the tree, and right-click on this element to get the Add menu (Add --> Non-Test Elements --> HTTP Proxy or HTTP(S) Test Script Recorder). In newer versions HTTP Proxy Server is renamed as HTTP(S) Test Script Recorder.  This is as shown below in version 2.8:


In Version 2.10:

In this post we will follow with version 2.8.
Once the HTTP Proxy Server is added we have below fields:

Parameters for the above screen:
Attribute
Description
Required
Name
The descriptive name for this element that is shown in the tree.
No
Port
The port that the HTTP Proxy listens to. 8080 is the default, but you can change it.
Yes
Target Controller
The controller where the proxy will store the generated samples. By default, it will look for a Recording Controller and store them there wherever it is.
Yes
Grouping
Whether to group samplers for requests from a single "click" (requests received without significant time separation), and how to represent that grouping in the recording:
  • Do not group samplers: store all recorded samplers sequentially, without any grouping.
  • Add separators between groups: add a controller named "--------------" to create a visual separation between the groups. Otherwise, the samplers are all stored sequentially.
  • Put each group in a new controller: create a new Simple Controller for each group, and store all samplers for that the group in it.
  • Store 1st sampler of each group only: only the first request in each group will be recorded. The "Follow Redirects" and "Retrieve All Embedded Resources..." flags will be turned on in those samplers.
  • Put each group in a new transaction controller: create a new Transaction Controller for each group, and store all samplers for that group in it.
The property proxy. pause determines the minimum gap that JMeter needs between requests to treat them as separate "clicks". The default is 1000 (milliseconds) i.e. 1 second. If you are using grouping, please ensure that you leave the required gap between clicks.
Yes
Capture HTTP Headers
Should headers be added to the plan? If specified, a Header Manager will be added to each HTTP Sampler. The Proxy server always removes Cookie and Authorization headers from the generated Header Managers. By default, it also removes If-Modified-Since and If-None-Match headers. These are used to determine if the browser cache items are up to date; when recording one normally wants to download all the content. To change which additional headers are removed, define the JMeter property proxy.headers.remove as a comma-separated list of headers.
Yes
Add Assertions
Add a blank assertion to each sampler?
Yes
Regex Matching
Use Regex Matching when replacing variables? If checked replacement will use word boundaries, ie it will only replace word matching values of the variable, not part of a word. A word boundary follows Perl5 definition and is equivalent to \b.
Yes
Type
Which type of sampler to generate (the Java default or HTTPClient)
Yes
Redirect Automatically
Set Redirect Automatically in the generated samplers?
Yes
Follow Redirects
Set Follow Redirects in the generated samplers?
Note: see "Recording and redirects" section below for important information.
Yes
Use Keep-Alive
Set Use Keep-Alive in the generated samplers?
Yes
Retrieve all Embedded Resources
Set Retrieve all Embedded Resources in the generated samplers?
Yes
Content Type filter
Filter the requests based on the content-type - e.g. "text/html [;charset=utf-8 ]". The fields are regular expressions which are checked to see if they are contained in the content-type. [Does not have to match the entire field]. The include filter is checked first, then the exclude filter. Samples which are filtered out will not be stored. Note: this filtering is applied to the content type of the response
No
Patterns to Include
Regular expressions that are matched against the full URL that is sampled. Allows filtering of requests that are recorded. All requests pass through, but only those that meet the requirements of the Include/Exclude fields are recorded . If both Include and Exclude are left empty, then everything is recorded (which can result in dozens of samples recorded for each page, as images, stylesheets, etc are recorded). If there is at least one entry in the Include field, then only requests that match one or more Include patterns are recorded .
No
Patterns to Exclude
Regular expressions that are matched against the URL that is sampled. Any requests that match one or more Exclude pattern are not recorded .
No
Start Button
Start the proxy server. JMeter writes the following message to the console once the proxy server has started up and is ready to take requests: "Proxy up and running!".
N/A
Stop Button
Stop the proxy server.
N/A
Restart Button
Stops and restarts the proxy server. This is useful when you change/add/delete an include/exclude filter expression.
N/A

Once the above required parameters are set. Click on Start.
Note: To record in the browser we need to set the same proxy settings in browser also as shown below:


Launch the application in the browser and  run the required scenario. Jmeter will capture the requests as shown below. We see there are lot of .gif files captured before the actual login request. We can exclude these from recording.


If we observe the HTTP Request of each, we get information like Implementation, then Method GET/POST.  Also the Parameters section shows the Parameters and values passed. For example, I have used credentials username as demo and password as demo. These are shown above.
This is how we can record using HTTP Proxy Server.
Ideally use private browsing mode when recording the session. This should ensure that the browser starts with no stored cookies, and prevents certain changes from being saved. For example, Firefox does not allow certificate overrides to be saved permanently.

Note 1: The most important thing to do is filter out all requests you aren't interested in. For instance, there's no point in recording image requests (JMeter can be instructed to download all images on a page). These will just clutter your test plan. Most likely, there is an extension all your files share, such as .jsp, .asp, .php, .html or the like. These you should "include" by entering ".*\.jsp" as an "Include Pattern". Alternatively, you can exclude images by entering ".*\.gif" as an "Exclude Pattern". Depending on your application, this may or may not be a better way to go. You may also have to exclude stylesheets, javascript files, and other included files. Test out your settings to verify you are recording what you want, and then erase and start fresh. The matching is case-sensitive.

Note 2 : If JMeter does not record any samples, check that the brower really is using the proxy. If the browser works OK even if JMeter is not running, then the browser cannot be using the proxy. Some browsers ignore proxy settings for localhost or 127.0.0.1; try using the local hostname or IP instead.

Note 3: The error "unknown_ca" probably means that you are trying to record HTTPS, and the browser has not accepted the JMeter Proxy server certificate.


Comments

  1. Note 2 really helped me debug my problem of not getting recorded. My set localhost to all proxies it worked!
    Thank you!

    ReplyDelete
  2. Thank you, very explaining in detail. Keep up the good work.

    ReplyDelete
  3. Hi, good explanation. Just want to give +1 on the hearts effect onclick. just made my day :)

    ReplyDelete
  4. NIce article for Record and Playback feature in Jmeter.thanks for sharing...

    ReplyDelete
  5. Very interesting and informative blog..thanks for sharing...
    multiple proxies

    ReplyDelete

Post a Comment

Popular posts from this blog

How to use a value between two different threads in Jmeter

Steps to Analyze AWR Report in Oracle

Correlation and checking in Results