Recording on JMeter
Welcome to Learn JMeter Series! This series helps you to learn Apache JMeter in a much simpler way with the relevant examples and exercises.
Join the DZone community and get the full member experience.Join For Free
Welcome to Learn JMeter Series! This series helps you to learn Apache JMeter in a much simpler way with the relevant examples and exercises. This tutorial focuses on Recording on JMeter.
What Is Recording?
To get started with application performance testing, the first step in JMeter is recording your business transactions. Recording the business flow helps to expedite the process of creating test plans. Otherwise, you will be spending more time manually crafting the requests.
Almost any GUI-based performance testing tool offers a way to record the application via proxy. But CLI based tools such as k6 adopt a different approach when it comes to recording.
How to Get Started With Recording in JMeter?
In JMeter, adding a Non-Test element to your test plan enables you to capture the network traffic. Right-click on Test Plan > Add > Non-Test Elements > HTTP(S) Test Script Recorder. This will add the recording capability to JMeter.
To begin recording, understand the business flow and have your input data ready. Preferably clear your cache and cookies from your favorite browser.
Configuring HTTP(S) Test Script Recorder
JMeter records the traffic via proxy. By default, JMeter uses 8888, but it can be configured based on your needs.
Now, open your favorite browser. In this case, I am using Mozilla Firefox, then launch the proxy settings and configure the same proxy as JMeter.
In this series, we are going to use multiple demo websites. To demonstrate the recording capability, we are going to use the Bank of Anthos demo app.
Below is the business flow:
- Launch this link.
- Sign in with the default credentials.
- Click on Deposit Funds.
- Enter 10 to the default external account, and click on Deposit.
- Sign out.
Go back to JMeter, add a Thread Group and, in HTTP(S) Test Script Recorder, select the Target Controller as Test Plan > Thread Group as shown below.
Then, click on Start. If you get a pop-up, that is fine, click on OK, and then go back to Firefox and launch this link.
Once the recording is done, click on the Stop button. In your Thread Group, you can see the recorded elements as shown below.
By default, JMeter records everything. It is your responsibility to remove unwanted requests such as ads, fonts, third-party calls, etc.
But, you can avoid unwanted requests using the network filtering option in JMeter. Click on Requests Filtering in HTTP(S) Test Script Recorder.
Add the below regular expressions under URL Patterns to include:
Then, repeat the recording. You will get only the relevant HTTP requests for your test plan.
After the recording is done, it is time to smoke test the recorded elements. Add the View Results Tree listener to the test plan, by right-clicking on Thread Group > Add > Listener > View Results Tree.
You will get the below error when you replay the test plan. That is fine. Let us fix this in a moment.
How Do You Fix the Test Plan?
Whenever you work on a web application in JMeter, always add Cache Manager, Cookie Manager, and DNS Cache Manager from the Config Element category to the test plan. If you replay now, you will not see any errors.
The above test plan cannot be used for load testing yet. There are a lot of enhancements to be done. Eventually, we will cover everything.
In this article, you have learned how to capture business transactions in JMeter via proxy and a couple of tips and tricks for successful smoke testing. In our next article post, we will discuss Data Parameterization in JMeter.
Published at DZone with permission of NaveenKumar Namachivayam, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.