Recording on JMeter
Tags: performance, testing, tutorial, webperf
Published: 2021-08-17 14:13:59

<!-- wp:paragraph -->
<p>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 <strong>Recording on JMeter</strong>. </p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><a href="https://qainsights.com/introduction-to-jmeter-elements/">Introduction to JMeter Elements</a></li><li><a href="https://qainsights.com/downloading-and-installing-jmeter/">Downloading and Installing JMeter</a></li><li><a href="https://qainsights.com/introduction-to-apache-jmeter/">Introduction to Apache JMeter</a></li><li><a href="https://qainsights.com/jmeter-execution-order-and-scoping-rules/" target="_blank" rel="noreferrer noopener">JMeter Execution Order and Scoping Rules</a></li></ul>
<!-- /wp:list -->

<!-- wp:heading -->
<h2>What is Recording?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"4d8a40b8"} -->
<h2 class="gb-headline gb-headline-4d8a40b8 gb-headline-text">How to get started with recording in JMeter?</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>In JMeter, by adding a Non-Test element to your test plan, enables you to capture the network traffic. Right click on <strong>Test Plan &gt; Add &gt; Non-Test Elements &gt; HTTP(S) Test Script Recorder</strong>. This will add the recording capability to JMeter.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>To begin recording, understand the business flow and have your input data ready. Preferably clear your cache and cookies from your favorite browser.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"a9a37846"} -->
<h2 class="gb-headline gb-headline-a9a37846 gb-headline-text">Configuring HTTP(S) Test Script Recorder</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>JMeter records the traffic via proxy. By default, JMeter uses 8888, but it can be configured based on your needs. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8568,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image.png" alt="" class="wp-image-8568"/></a><figcaption><strong>Mozilla Firefox Proxy Settings</strong></figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>In this series, we are going to use multiple demo websites. To demonstrate the recording capability, we are going to use <strong>Bank of Anthos</strong> demo app https://bank-of-anthos.xyz/login </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Below is the business flow:</p>
<!-- /wp:paragraph -->

<!-- wp:list {"ordered":true} -->
<ol><li>Launch https://bank-of-anthos.xyz/login</li><li>Sign in with the default credentials,</li><li>Click on <strong>Deposit Funds</strong></li><li>Enter 10 to the default external account, click on <strong>Deposit</strong></li><li>Sign out </li></ol>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Go back to JMeter, add a <strong>Thread Group</strong> and in <strong>HTTP(S) Test Script Recorder</strong>, select the <strong>Target Controller</strong> as <strong>Test Plan &gt; Thread Group</strong> as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":8569,"sizeSlug":"full","linkDestination":"media"} -->
<figure class="wp-block-image size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-2.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-2.png" alt="Recording on JMeter" class="wp-image-8569"/></a><figcaption>Recording on JMeter</figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Then, click on <strong>Start</strong>. If you get a pop-up, that is fine, click on OK, and then go back to Firefox and launch the https://bank-of-anthos.xyz/login URL.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Once the recording is done, click on the <strong>Stop </strong>button. In your <strong>Thread Group</strong>, you can see the recorded elements as shown below.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8570,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-3.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-3.png" alt="Vanilla Recording" class="wp-image-8570"/></a><figcaption>Vanilla Recording</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>By default, JMeter records everything. It is your responsibility to remove unwanted requests such as ads, fonts, third party calls etc.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>But you can avoid unwanted requests using the network filtering option in JMeter. Click on <strong>Requests Filtering </strong>in <strong>HTTP(S) Test Script Recorder</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Add the below regular expressions under URL Patterns to include.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>(?i)bank-of-anthos.xyz(.*)</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>Then repeat the recording. You will get only the relevant HTTP requests for your test plan.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8571,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-4.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-4.png" alt="Optimized Recording" class="wp-image-8571"/></a><figcaption>Optimized Recording</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"6295e690"} -->
<h2 class="gb-headline gb-headline-6295e690 gb-headline-text">Smoke Test</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>After the recording is done, it is time to smoke test the recorded elements. Add the <strong>View Results Tree</strong> listener to the test plan, by right-clicking on <strong>Thread Group &gt; Add &gt; Listener &gt; View Results Tree</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>You will get the below error when you replay the test plan. That is fine. Let us fix this in a moment.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8573,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-5.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-5.png" alt="Smoke Testing" class="wp-image-8573"/></a><figcaption>Smoke Testing</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:generateblocks/headline {"uniqueId":"da9677df"} -->
<h2 class="gb-headline gb-headline-da9677df gb-headline-text">How to fix the test plan?</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>Whenever you work on a web application in JMeter, always add <strong>Cache Manager, Cookie Manager and DNS Cache Manager</strong> from the <strong>Config Element</strong> category to the test plan. If you replay now, you will not see any errors.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":8574,"sizeSlug":"full","linkDestination":"media"} -->
<div class="wp-block-image"><figure class="aligncenter size-full"><a href="https://qainsights.com/wp-content/uploads/2021/08/image-6.png"><img src="https://qainsights.com/wp-content/uploads/2021/08/image-6.png" alt="Clean Run" class="wp-image-8574"/></a><figcaption>Clean Run</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Above test plan cannot be used for load testing yet. There are lot of enhancements to be done. Eventually we will cover everything.</p>
<!-- /wp:paragraph -->

<!-- wp:generateblocks/headline {"uniqueId":"cc67c4df"} -->
<h2 class="gb-headline gb-headline-cc67c4df gb-headline-text">Conclusion</h2>
<!-- /wp:generateblocks/headline -->

<!-- wp:paragraph -->
<p>In this blog, 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 blog post, we will discuss <strong>Data Parameterization in JMeter</strong>.</p>
<!-- /wp:paragraph -->