Watch YouTube Video: JMeter Script Recording & Best Practices
Apache JMeter is a Java-based tool which records the communication between client i.e. end-user and server and converts this communication into a test script. This test script is used to generate the load on the server. To record the communication through JMeter and convert it into a script, you must have below listed 5 pre-requisites:
- Application or Website Link
- Test Data like user credentials
- Transaction Flow Diagram / Navigation Flow / Use Case
- Web-browser (by default you have) like Chrome, Firefox etc.
- Apache JMeter (How to install?)
JMeter Script Recording Steps:
1. Launch JMeter by navigating to <JMETER_HOME>/bin (Example: C:\apache-jmeter-5.3\bin)
2. Click jmeter.bat (Windows) or Enter command ‘jmeter’ (Linux/Unix). Read the article to know more on different Launching modes of JMeter
3. Select ‘Test Plan’ on the tree
4. Right-click on the ‘Test Plan’ and add a ‘Thread Group’
5. Select ‘Thread Group’ and right-click to add ‘Recording Controller’.
Note: You can also use ‘Transaction Controller’ instead of ‘Recording Controller’.
6. Right-click on the ‘Test Plan’ and add ‘HTTP(S) Test Script Recorder’ which is a ‘Non-test Element’.
7. Under ‘HTTP(S) Test Script Recorder’, add ‘View Results Tree’ listener by right-clicking on ‘HTTP(S) Test Script Recorder’ element and provide a .jtl file path in the Filename. This .jtl file is required to save the recording logs.
8. In ‘HTTP(S) Test Script Recorder’, under ‘Global Settings’ section, provide the port number as ‘8080’ and application URL in ‘HTTPS Domain’ text field. While providing application URL do not use http, https, : and /.
9. In ‘HTTP(S) Test Script Recorder’, under ‘Test Plan Creation’ tab, the default value of the ‘Target Controller’ is ‘Use Recording Controller’ In case you use ‘Transaction Controller’ as shown in step 5 then select the particular transaction controller as target controller.
10. Optional Step: On HTTP(S) Test Script Recorder, under ‘Request Filtering’ tab, click the ‘Add’ button in ‘URL Patterns to Include’. This will create a blank entry; write ‘.*\.html’.
Also click the ‘Add suggested Excludes’ button in ‘URL Patterns to Exclude’ section, this will add a new row i.e. (?i).*.(bmp|css|js|gif|ico|jpe?g|png|swf|woff|woff2). After excluding such request pattern, JMeter does not record those requests which have excluded keywords. You can also add new custom pattern or keyword in this list.
11. Now, Launch Browser (Chrome/Firefox/Edge) and set Manual Proxy.
Address: localhost or IP address of your system
Refer respective screenshot:
12. In case the application is secured (https) then you need to add ‘JMeter Root CA certificate’ to the browser. More details are given in ‘How to record JMeter script for a secured (https) application?‘.
13. Go back to JMeter, in ‘HTTP(S) Test Script Recorder’ and click the ‘Start’ button.
14. A ‘Root CA Certificate’ pop-up will open. Click ‘OK’.
15. Go to your browser and type the application URL and follow the transaction flow. You can see a floating ‘Recording Bar’ while recording the flow.
16. Once navigation is completed, click the ‘Stop’ button on Recording Bar or in ‘HTTP(S) Test Script Recorder’.