JMeter provides an easy way to record and create a Test Plan automatically. You can do this by recording the test steps in JMeter, using the Recording Controller. This is especially useful if you have an elaborate test plan or if you do not want to add elements for each step, manually.
We make use of the HTTP(s) Test Script Recorder in JMeter in order to record the activities. It was earlier known as the HTTP Proxy Server.
Recording the test is one of the easiest ways to build a test plan. It helps you to save the effort in adding the test step manually.
In Recorded Testing, JMeter watches and records user activities when you browse the web application and perform normal operations such as login, signup, search etc.
Practical hands on exercise in Recording Test Plan in JMeter
In our hands on practical exercise, we will record a session of us browsing some of the news stories on the CNN website. Follow the steps below on your machine to practice recording in JMeter.
Step 1. Add Thread Group
Add Thread Group to the Test Plan, as explained in previous topics and configure the Thread Group as shown below.
Step 2. Add HTTP Request Default
Right click on Thread Group and choose Add > Config Element > HTTP Request Defaults
Configure the HTTP Request Default as shown below
Step 3. Add an HTTP Cookie Manager
Right click on Thread Group and choose Add > Config Element > HTTP Cookie Manager.
(As discussed before HTTP Cookie Manager works like web browser cookies and it stores the cookies used by the website)
Step 4. Add Recording Controller
Right click on Thread Group and choose Add > Logic Controller > Recording Controller.
The Recording Controller is added to the Thread Group. It does not have any configuration options. Its only used as a placeholder to store samples when recording.
Step 5. Add HTTP(S) Test Script Recorder, earlier called HTTP Proxy Server
HTTP(s) Test Script Recorder will record all the user operations and save it to the Test Plan. The recorder can only be added to the WorkBench.
Right click on the WorkBench and choose Add > Non-Test Elements > HTTP(S) Test Script Recorder.
None of the items in the Workbench are included in the Test Plan and they will not be saved when you save the Test Plan.
HTTP(S) Test Script Recorder configuration options
Global Settings: By default, the global setting is 8080 but we will change it to other port number to avoid any conflict with other apps. In this case, we choose port number 8082.
Target Controller: We will leave this set to Use Recording Controller in our exercise. This will add the recorded samples as child elements of the Recording Controller which we added in Step 4. You can also use the other option in the drop down “Test Plan > Thread Group”, which will add the recording samples to the Thread Group in the Test Plan.
Content-type filter: You can configure JMeter to include or exclude what you want to record.
The Content-type filter can be used to either include only the types of content you want to request using the Include parameter (example: html, php, etc) or to exclude the types of content you do not want to request using the Exclude parameter (example: jpg, png, js, etc).
JMeter uses regular expressions as the input in this field. In this example we will not be restricting files by content types.
URL Patterns to Include / Exclude: You can also choose to include or exclude URL patterns in the recording using the URL Patterns to Include and URL Patterns to Exclude fields respectively. You can use regular expressions to specify the pattern. In our example, we will limit the recording to include only URL’s ending with “html”. We can do this by adding the pattern “.*html”
Step 6. Add Listener
Once we record the test, we will run the test using JMeter. We need to add a Listener so that we can view the results. Right click on the Thread Group and choose Add > Listener > View Results in Table.
Step 7. Configure Proxy Setting for your Browser
In the previous step, we have started the HTTP Test Script Recorder and it is going to act as the proxy server for our browser. In this step, we use configure our browser to use this proxy server on “localhost” listening to port 8082.
In our example, we will use the Firefox browser.
Open the Options page in Firefox by entering about:preferences in the address bar. You can also open the options page using the keyboard shortcut Alt + T and clicking on Options.
Choose Advanced from the left hand menu and choose Network tab. Click on Settings button under Connection > Configure how Firefox connects to the Internet.
Configure the Connection Settings dialog box as shown below. Set HTTP Proxy to localhost and Port to 8082. Click OK to save the configuration.
Step 8. Start the Test Script Recorder
Click on the HTTP(S) Test Script Recorder in the WorkBench and click the Start button at the bottom of the right pane to start the recording.
JMeter will display a dialog box about Root CA Certificate, click OK to proceed.
Now open Firefox, visit cnn.com, click on links to stories, categories and perform any actions that you want to test.
You will notice that JMeter will add samples under the Recording Controllers based on your configuration in the HTTP(S) Test Script Recorder.
Once you are done, go back to JMeter, click the Stop button to stop the script. Now JMeter would have already recorded all the activities you performed.
Since JMeter has added samplers to your Test Plan, you should save the Test Plan.
Step 9. Run the Test Script
Now that you have the recorded test plan, you ready to run it.
Click Run button on menu bar to run the test script, JMeter will playback the test script and display the result as shown below.
This topic includes a sample Test Plan with setting as above, you can tweak the setting in the plan to experiment with the different options.
• In case you do not see any samplers under the Recording Controller, ensure that the Port setting in the HTTP(S) Test Script Recorder match the ones in your browsers proxy server setting.
• Check the Content-type filters and URL Patterns to Include / Exclude fields to make sure you have not entered incorrect options.
You can download HTTP Script Recorder JMeter Test Plan from our website.
When you are done practicing the above example, you move on to the next topic on JMeter Best Practises for Performance and Load Testing.