A quick overview of Gatling & basic Gatling Script

Reading Time: 4 minutes

Hello Readers,
In this blog, we will get a quick overview about what is gatling & how to write gatling script.

Gatling is one of the performance testing tools that we can use in the load generation if development is focus on http support . Gatling is an open-source load and performance-testing framework based on Scala, Akka and Netty.

Create first gatling project

We can create the gatling project from command line/terminal or direct from intellij. The easiest way to create a new project is by using an “archetype”. An archetype is a general skeleton structure or template for a project. To create the project we need to follow a few steps:-

1. Run the archetype plugin using command prompt by using the following command.

2. Once you press enter, you will see Maven downloading many Jar Files by resolving dependencies and downloading them as needed (only once).

3. Once all the jar files gets download, assign the groupId, artifactId, and the package name for your classes before confirming the archetype creation.

4. Once you provide all the require details, you will see a build success message and the location of the particular project that implies your project is successfully created.

5. Open the Generated Project using Intellij Idea and follow the below steps to open the project using Intellij.

File > Open > Select the directory for the generated project > Click on the pom.xml file

Once you click to open the pom.xml, you will notice that it takes a little time to load all the dependencies and the project structure. It will also contain the following launchers.

  • Gatling Engine
  • Gatling Recorder

The Gatling load test engine can be launch by right-clicking on the Engine class in your IDE. The target/Gatling directory will be use to store the simulation reports.

You can easily start the Recorder by right-clicking on the Recorder class in your IDE. The src/test/Scala directory will be use to construct the simulations. Here is an image reference to show how it’ll look once everything gets load.

Now, you are all set to write your first Gatling script.

Writing first gatling script

To start writing your first Gatling Script first of all we need to create a package with the name simulation under SRC > test > scala as shown below.

Once you have created the simulations folder, we need to create a class under that particular folder.

Now, you can start writing your script in that particular class. There are some general procedures to follow while writing your script.

Procedures to be follow for writing the scripts:-

  • The Package Name should be mentioned
  • Make sure to import all the important Gatling Classes
  • The Class should extend the Simulation Class
  • The script should consist of the below three integral parts
    • HTTP Configuration
    • Scenario
    • Setup
  • In the HTTP configuration part, we should provide the base URL to pass the header and the value.
  • Here, we give the scenario a name and execute the request by providing the request URL and an assertion for the particular request.
  • When it comes to the setup part, we must inject the number of concurrent users utilizing the setup method and pass the protocols.

The Script should be as follows:-

Once the script is ready, you can run it by

  • Clicking right on the ‘Engine’ option
  • Click Run Engine

After you click on run Engine, you will see the script run and you will be asked to enter the description of the run in the console. Once you have enter the description, you will get the output in the console along with the report link. If you want to view the report, all you have to do is just copy the report link and paste it into any browser.

Below are the images of how the generated report link looks like on browser.

Global Information Results

Statics Report

Detail Report

Reference

1.For installation:- https://gatling.io/

2.For setup gatling with maven:- https://blog.knoldus.com/starting-with-gatling-using-maven/

Please do check out our other blogs on a similar tech stack, https://blog.knoldus.com/category/tech-blogs/test-automation/.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading