Gatling is a powerful load testing tool designed to explore and measure the performance of various web applications. Of its many features, the recorder mode is the most useful one. This article will guide you through what a Gatling recorder is and how to use it effectively, from setup to execution.
Table of contents
- What is Gatling Recorder?
- Pros and cons of Gatling Recorder
- Different modes of Gatling Recorder
- Sample performance tests with Gatling Recorder
- Conclusion
What is Gatling Recorder?
The Gatling Recorder is an important tool of the Gatling load testing framework. It acts as a medium between user actions and test scripts. This tool intercepts HTTP/HTTPS traffic, which helps convert real-time user actions into simulation test scripts. Initially, it only supported Scala, but now it also supports Java.
Gatling Recorder captures each interaction as users navigate web applications, from simple clicks to complex form submissions. These captured scenarios are then converted into complete Gatling test script that is useful for performance testing. These Gatling scripts help testers run various concurrent users and easily load-test applications.
Pros and cons of Gatling Recorder
Pros
- Effortless test scenario generation
- Captures actual user behaviors
- Automates script creation
- Records complex user flows
- Generates Scala and Java scripts
Cons
- Requires understanding of Gatling syntax
- May not capture all interaction types
- Can record irrelevant requests
- Needs proper browser configuration
- Recorded Gatling scripts may need updates
Different modes of Gatling Recorder
HTTP Proxy
The Proxy mode in Gatling Recorder is a method for capturing HTTP/HTTPS traffic between a web browser and a website. In this mode, the Gatling Recorder acts as a medium that watches and records all requests and responses that pass through it. To use this mode, users must configure their browser settings to route internet traffic through the Gatling Recorder. Then, typically, set it up as a proxy server on your computer (localhost) using a specific port number. This mode is great for recording complex web sessions involving many requests and dynamic content. It captures all HTTP-based traffic, including AJAX requests and WebSocket communications.
HAR Converter
HAR (HTTP Archive) converter mode in Gatling Recorder provides a different approach for capturing web traffic for performance testing. Instead of operating as a live proxy, this mode helps users import the pre-recorded HAR files from the browser. These HAR files contain detailed logs of a web browser’s interactions and capture all the HTTP requests and responses created during the session. The data within a HAR file contains information such as Request and Response Headers, Timing Data, Cookies, Request Payloads, Redirects, and so on.
HAR mode is particularly useful when direct proxying is impossible or when test scenarios based on traffic captured under specific conditions are desired. Users can generate HAR files using browser developer tools and then import them into the Gatling Recorder.
Sample performance tests with Gatling Recorder
Before starting the following steps for the Gatling recorder, please refer to our previous article on setting up Gatling and its installation instructions.
Here, we will perform a sample performance test in HAR Converter mode.
Project set up
We’ll now use IntelliJ IDEA as our test editor to create a new Java project.
Once the project is created, the pom.xml file will be open by default.
To run Gatling tests, we need to add the Gatling Maven plugin and its dependencies to our pom.xml file.
Refer to our previous article for the complete updated script for the pom.xml file. Otherwise, you can refer to this.
After the pom file is configured, the next step is to move your resources folder to the src\test\ path.
Open the terminal by pressing Alt + F12 (in Widows) or option + F12 (in Mac).
Run the following command in the console:
mvn clean gatling:recorderCode language: CSS (css)
This command will clean the project and start the Gatling recorder.
Configure Gatling Recorder
Now, we will set up our Gatling recorder in HAR mode for the sample URL – https://github.com/alexwohlbruck/cat-facts?tab=readme-ov-file.
Select the HAR Converter mode from the drop-down menu in the top-right corner.
Give a name to your class. We will use this class name later in our sample tests.
You can edit the package name here; otherwise, the default package will be used.
Generate HAR file from browser
We will now open our preferred web browser (we’ve used Microsoft Edge on Windows here).
Press F12 to open Developer Tools and go to the Network tab.
F12 in Windows is the common keyboard shortcut to open dev tools in most web browsers. In Mac, you have to use command + option + I.
Enable the Preserve log check box if it has not already been checked.
Put the URL that you will be using for your load tests. Here, we will use https://github.com/alexwohlbruck/cat-facts?tab=readme-ov-file .
We are going to navigate to several pages on the website and do some actions that we want to test.
After completing our actions, click on the Export HAR icon. Give your HAR file a name, and the file will be downloaded.
Return to the Gatling Recorder page and click the Browse button to import the downloaded HAR file.
Try not to modify the default Simulation folder’s location.
Finally, click on the Start button.
Execute the tests
Navigate to the saved location of the HAR file and open that file with IntelliJ.
After importing your HAR file through the Gatling Recorder, most of our test structure, including the import statements, will be automatically generated.
Then, we have to add our test simulation class inside the pom.xml file:
<configuration>
<simulationClass>package_name.class_name</simulationClass>
</configuration>Code language: HTML, XML (xml)
Lastly, we must modify the number of virtual users for our load tests based on our requirements.
Then, go to the console tab and run the following command to start the execution:
mvn clean gatling:testCode language: CSS (css)
Once completed, Gatling will generate a detailed HTML report along with total request count, requests per sec, and response time distribution statistics.
Final thoughts on Gatling Recorder
In conclusion, Gatling Recorder is a powerful performance testing tool, offering different modes like HTTP Proxy and HAR Converter to simplify generating and executing test scenarios. Its capability to capture and convert real user interactions into test scripts makes it valuable for creating realistic load conditions. By effectively setting up and configuring Gatling Recorder, users can improve their performance testing strategies and ensure strong, scalable applications. Happy testing!
Don’t miss these
Follow our blog
Be the first to know when we publish new content.
- How to find an element in Selenium - October 5, 2024
- Resolved: SessionNotCreatedException - October 2, 2024
- Katalon Recorder Automation Overview - September 12, 2024