Performance Testing using Gatling Tool

Reading Time: 4 minutes

About Gatling

  • Gatling is a one of the performance testing tools that we can use in the load generation if development is focused on http support . Gatling is an open-source load- and performance-testing framework based on Scala, Akka and Netty.
  • Althouth It is developed in domain specific language but the tool help us with a GUI allowing us to record the scenario. Once we have complete recording the scenario the GUI creates the Scala script representing the simulation. Creating a Project Using the Archetype.
  • Although we can get Gatling bundles as a .zip we choose to use Gatling’s Maven Archetype. This allows us to integrate Gatling and run it into an IDE and make it easy to maintain the project in a version control system. Be careful as Gatling requires a JDK.References
  • Last but not least, Gatling’s architecture is asynchronous. This kind of architecture lets us implement virtual users as messages instead of dedicated threads, making them very resource cheap. Thus, running thousands of concurrent virtual users is not an issue.

Features of Gatling

Continuing the Gatling introduction, at a high level some of the features are:

Excellent support for HTTP Protocol – this makes Gatling a good choice for load testing any HTTP server or for calling APIs directly.

Simulation scripts written in Scala – if you don’t have much experience with Scala this can make scenario creation and maintenance more challenging. Fortunately Gatling comes with an expressive DSL that is self explanatory. Writing load test scenarios in Scala code allows for huge flexibility.

GUI Recorder – The Gatling recorder works as a proxy to capture all traffic in your user journey and then converts it into a Gatling scenario. This can be useful when creating a script for a more complex web application. Also useful as a starting point for generating a template Gatling scenario against a new application under test.

Code can be kept in VCS – as Gatling load test scenarios are just Scala code, they can be kept in the Version Control System. Alongside the production code. This makes scenario code easier to maintain.

Easily run tests as part of CI – Since the code is kept in the VCS, it is easy to run load tests in the Continuous Integration process. This is even easier because load tests in Gatling run from a single machine. In other tools a distributed environment of load injectors is often required for test execution, which is more complex to implement. Scenarios can be configured to fail the CI build if a certain threshold is breached, such as number of failures or high transaction response times.

Creating a Project Using the Archetype

Although we can get Gatling bundles as a .zip we choose to use Gatling’s Maven Archetype. This allows us to integrate Gatling and run it into an IDE and make it easy to maintain the project in a version control system. Be careful as Gatling requires a JDK.
From the command line, type:

mvn archetype:generate

Then, when prompted:

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):

Type:

Gatling

From the command line, type:

mvn archetype:generate

Then, when prompted:

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):

Type:

Gatling

Define a Scenario

We should have the Define Scenario before launching the Recorder. It will be a representation of what really happens when users navigate a web application.
We will use this URL http://computer-database.gatling.io for explaining the things.Our simple scenario could be:

  • A user arrives at the application.
  • Searches for ‘amstrad’.
  • Open one of the related models.
  • Go back to the home page.
  • Iterate through pages.

Configuring the Recorder

After launching the Recorder class from the IDE. The GUI lets you configure how requests and responses will be recorded. Follow the below options:

  • 8000 as listening port
  • org.baeldung.simulation package
  • RecordedSimulation class name
  • Follow Redirects? checked
  • Automatic Referers? checked
  • Black list first filter strategy selected
  • .*\.css, .*\.js and .*\.ico in the black list filters

Configure the browser to use port (8000) selected during configuration. This is the port our browser must connect to so that the Recorder is able to capture our navigation.
Here is how to do with Firefox, open the browser Advanced settings, then go to the Network panel and update the connection settings:

Recording the Scenario

After Configuration, Now we can record the scenario that we defined above . The step are given below:

  • Initiate the recording by clicking the ‘Start’ bReferencesutton
  • Go to the website: http://computer-database.gatling.io
  • Search for models with ‘amstrad’ in their name
  • Select ‘Amstrad CPC 6128′
  • Go back to home page
  • Iterates several times through the model pages by clicking on Next button
  • Click on ‘Stop & save’ button

    The Simulation will be generated in the stated package ( org.baeldung ) defined during the configuration under the name RecordedSimulation.scala

Run a Simulation with Maven

To run our recorded simulation we need to update our pom.xml:

<plugin>
    <groupId>io.gatling</groupId>4.10
    <artifactId>gatling-maven-plugin</artifactId>
    <version>2.2.4</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals><goal>execute</goal></goals>
            <configuration> 
                <disableCompiler>true</disableCompiler> 
            </configuration>
        </execution>
    </executions>
</plugin>

This let us execute the simulation at the test phase. To start the test just run: mvn test
The path to HTML reports will be appearing in console after completing the simulation.
Note: configuration <disableCompiler>true</disableCompiler> is used because we will be using Scala with maven this flag will ensure that we do not end up compiling our simulation twice. More details are available on Gatling docs.

Reviewing the Result

If we open the index.html fetched from console of ID after successful execution of script at the suggested location the reports look like as follow:

Conclusion

We explored load testing an HTTP server with Gatling. The tools allow us to record a simulation based on a defined scenario with the help of a GUI interface. After the recording is done we can launch our test. The test report will be in a form of HTML form.References
To build up our example we have chosen to use a maven archetype. This helps us to integrate Gatling and run it into an IDE and make it easy to maintain the project in a version control system.​​

References : https://gatling.io/ , https://www.udemy.com/course/performance-testing-using-gatling/learn/lecture/13525518?start=1#overview

Knoldus-blog-footer-image

Written by 

I am enthusiastic about everything that relates to software quality assurance and control. I am having more than 7+ years of experience in Developing Software Testing Solutions ( Manual +Automation ) for Standalone Applications, Web Applications & Mobile Applications. Well-versed with core QA concepts and well versed in designing automation frameworks in a microservice environment. Having good hands-on experience in automation tools like ReadyAPI, SoapUI, postman.io, rest-assured.io, gatling.io, Selenium (Java & Scala), and others. Having expertise in QA & QC for different domains and Agile Scrum methodology along with Team Management & project management.

Leave a Reply