Recording a script via HTTP(S) Test Script Recorder
Recording scripts is where you will spend most of your time. It is often the first step to develop test plans for applications. Though you can develop test plans manually by building them from within the JMeter GUI, or generating them via some domain-specific language (DSL), recording scripts by JMeter's HTTP(S) Test Script Recorder is one of the available options you have when building your test plans.
How to do it…
In this recipe, we cover how to record test scripts with HTTP(S) Test Script Recorder. Perform the following steps:
- Start JMeter. Perform the following steps:
- Open the command-line prompt
- Change to the directory of your JMeter install (
JMETER_HOME
) - Change to the
bin
directory - Execute the following command:
For Windows, type the following command:
jmeter.bat
For Mac OS/Unix, type the following command:
./jmeter
- Once the GUI is opened, click on the Templates… button (the icon that appears immediately to the right of the new test plan icon) on the toolbar.
Note
Templates were added in JMeter 2.10, so don't expect to see them in versions prior to that.
- In the drop-down menu of the Select Template box, choose Recording and click on the Create button.
- Click on the HTTP(S) Test Script Recorder element (under WorkBench) and change Port (under Global Settings) from
8888
to7000
.- You can use a different port if you want to. What is important to choose is a port that is not currently used by an existing process on the machine. The default is
8888
.
- You can use a different port if you want to. What is important to choose is a port that is not currently used by an existing process on the machine. The default is
- Leave the rest of the components with the default set values.
- The template does an excellent job and is configured with sensible defaults. The defaults provide the following:
- Target the recorded actions to Recording Controller added by the template.
- Group a series of requests that constitute a page load. We will see more on this topic later.
- Instruct the script recorder to bypass recording requests of a series of elements that are not relevant to test execution. These include JavaScript files, style sheets, and images.
- Add the often-used components, including user-defined variables, HTTP Request Defaults, and HTTP Cookie Manager, to the test plan.
- Add Thread Group and Recording Controller to the test plan.
- Add a View Results Tree listener to view results of the test plan.
- Click on the Start button at the bottom of the HTTP(S) Test Script Recorder component.
With these settings, the test script recorder server will start on the port 7000
, monitor all requests going through that port, and record them to a test plan using the default recording controller. For details, see the following screenshot:
How it works…
These steps instruct JMeter to act as an HTTP proxy and listen for incoming and outgoing requests from your browser to the Internet on the assigned port, in our case 7000
.
We now need to configure the browser to use the proxy server we just configured and redirect requests to the assigned port. There are several ways to do that, but we will focus here on the two most common ways.
There's more…
Modern browsers have a vibrant and active plugin ecosystem that allows you to extend the capabilities of your browser with an added plugin. FoxyProxy is one such plugin (http://getfoxyproxy.org/). It is a neat add-on for a browser that allows you to set up various proxy settings and toggle between them on the fly, without having to mess around with system settings on the machine. It really makes the work hassle free. Thankfully, FoxyProxy has a plugin for all major browsers including Google Chrome, Firefox, and Internet Explorer. If you are using any of those, you are lucky; head over and grab it!
Changing the machine system settings
The other common way to configure the browser is to change the system settings. The following are the details on how to configure Windows and Mac OS.
On Windows OS, perform the following steps to configure a proxy:
- Navigate to Start | Control Panel | Network and Internet | Internet Options.
- In the Internet Options dialog box, click on the Connections tab.
- Click on the LAN Settings button.
- To enable the use of a proxy server, check the Use a proxy server for your LAN (These settings will not apply to dial-up or VPN connections) box as shown in the following screenshot.
- In the proxy Address box, enter
localhost
in the IP address. - In the Port number text box, enter
7000
(to match the port you set up for your JMeter proxy earlier). - If you want to bypass the proxy server for the local IP addresses, select the Bypass proxy server for local addresses checkbox.
- Click on OK to complete the proxy configuration process. This is shown in the following screenshot:
On Mac OS, perform the following steps to configure a proxy:
- Navigate to System Preference | Network | Advanced….
- Go to the Proxies tab.
- Check Web Proxy (HTTP).
- Under Web Proxy Server, enter
localhost
. - For port, enter
7000
(to match the port you set up for your JMeter HTTP proxy earlier). - Do the same for Secure Web Proxy (HTTPS).
- Click on OK, as shown in the following screenshot:
For all other systems, consult the related operating system documentation.
With both JMeter's HTTP(S) Test Script Recorder and browser configured to use it, we are now ready to record a test. Perform the following steps:
- Point your browser to a website of your choice.
- Navigate to a few links.
- Notice that all user actions are being captured under the Thread Group component in the JMeter GUI.
- Stop the recording by stopping HTTP(S) Test Script Recorder.
The HTTP(S) Test Script Recorder server is set up to listen to requests on a particular port and then set the browser or system to redirect all requests to the assigned port. This allows us to capture the user actions as they interact with web applications, allowing us to replay their actions like we did in the Executing a test script recipe.
See also
- The Recording scripts via the Chrome browser extension recipe in Chapter 8, Beyond the Basics
- The Writing Test scripts through Ruby DSL recipe
- The Converting HTTP web archives (HAR) to JMeter test plan recipe