Introduction to Gatling


In this tutorial, we will learn how to install Gatling, and perform our first load test using the recorder on Windows. Let’s first understand what Gatling is.

What is Gatling?

Gatling is an open-source load and performance testing framework based on Scala, Akka and Netty.[1]

What are the advantages of Gatling?

  • Free and open source.
  • Powerful yet efficient system source management.
  • Operating system and browser independent.
  • Supports ‘Http’, ‘Websocket’, ‘Server-sent events’, ‘JMS’ protocols.

How to install Gatling?

Installing Gatling is pretty easy. Go to http://gatling.io/download/ and click on ‘Download Now’.

Extract the folder to the path of your choice. That’s it!

Install JDK

Gatling requires JDK. How to install JDK has explained in this article on step 4.

How to prepare performance test scenarios?

It is time to write our first load test. There are two ways of preparing a test, recording and writing your own test using Scala. We will talk about writing your own test in Scala later. In this tutorial, we will cover recording a scenario.

Navigate to the folder where you have extracted the gatling. On the “\bin” you will see two batch files, gatling.bat and recorder.bat.

Click on recorder.bat,

First, we need to define the port that recorder will listen. The default value is 8000. If that port is not in use on your computer, you can use the default value. Then name your class (i.e project) and click on start!

Since recorder listen to a pre-defined port, we need to configure the browser. For Google Chrome and Internet Explorer, go to ‘Control Panel’, select ‘Internet options’ and navigate to ‘Connections’ tab. Inside this tab click on ‘LAN settings’. Here deselect ‘Automatically detect settings’ if it is selected. Check ‘Use a proxy server for your LAN, change the address to ‘127.0.0.1’ and port to the defined value on gatling recorder. Click ‘Ok’.

If you are using Firefox, click on the menu button located on top right. Then click on ‘Options’.

Go to ‘Advanced’ tab on left menu, and there under ‘Network’ tab, click on ‘Settings’.

Select ‘Manual Proxy Configuration’, set ‘Http Proxy’ to ‘192.0.0.1’ and port to the defined value.

Now we are ready to record a test. Open the browser you have configured and simulate the user behavior that you would like to test. Do not forget to add some think time since a normal user would stop and think before clicks on a link on the web page.

For this tutorial, I will navigate to ‘www.swtestacademy.com’, wait a few seconds and then search ‘Gatling’.

Now let’s stop the recorder. Notice Gatling recorder recorded our steps and list the entire requests on ‘Executed Events’ section.

Congratulations you have recorded your first load test! It is saved under “user-files\simulations”. Now it is time to run it.

How to execute performance test with Gatling?

Go to “\bin” folder again and this time click on “gatling.bat”.

You will see the simulation you have recorded on the simulations list. Type the number (‘0’ in this example) related to your simulation and hit ‘enter’. You might pass simulation id for now and you might type some description for your simulation.

Once you hit enter, test will start and you will see the results in the end.

A detailed report has generated under “\results”. We will cover how to read load testing metrics on another article.

Notice this test only created one user. If we would like to change the simulation (i.e how you inject users), we need to edit the simulation code generated by the recorder.

Navigate to “\user-files\simulation”. You wil see the scala file ‘FirstLoadTest’. You can edit the file with a text editor of your choice or with an IDE (You might give IntelliJ’s Scala plugin a try).

Once the file is opened, you will notice that the recorder converted every step into a scala code. Now we need to choose how we would like to simulate users. If you like to learn different types of simulating users, go here. In this tutorial, I will ramp users up to 100 users in 60 seconds.

Each gatling load test requires ‘setUp’ function. For changing the simulation, we need to edit this function. By default, one user is created by gatling. That is done by, ‘atOnceUsers’ function. For changing the simulation we need change this function. The function we are looking for ramping users up is ,as the name suggests, ‘rampUsers’.

Edit the setUp function from this;

To this;

After saving your scala file, navigate back to “\bin” and double-click “gatling.bat”. Re-run the “FirstLoadTest” again.

You will observe that it will create 100 users in 60 seconds and completes the load test.

Congratulations! You wrote you first load test using Gatling!

Thanks
-Ege

javafx

Database Operations in JavaFX

By Onur Baskirt / Apr 1, 2016 / 56 Comments
Before started this section, please check the first article and learn How to Start JAVAFX! http://www.swtestacademy.com/getting-started-with-javafx/ At first, part of JavaFX tutorial series, we created a sample JavaFX project, designed the draft version of the UI and set up an...
rest assured

REST API Testing with Rest Assured

By Onur Baskirt / Mar 8, 2016 / 32 Comments
Outline In this post, I will explain what is API and API testing, what is the difference between SOAP and REST services, and how to test REST APIs with Rest Assured Library. What is API? API stands for Application Programming...
extentreports

How to Write Effective CSS Locators

By Onur Baskirt / Oct 1, 2017 / 0 Comments
Hi all, in this tutorial, I will describe you how to write effective CSS locators to interrogate web elements for your automation projects. As a rule of thumb, your interrogation strategy should be in below order: First try to use...
extentreports

Selenium-11: Execute JavaScript with JavascriptExecutor

By Onur Baskirt / Jan 27, 2016 / 15 Comments
Outline Sometimes we cannot handle some conditions or problems with Webdriver, web controls don't react well against selenium commands. In this kind of situations, we use Javascript. It is useful for custom synchronizations, hide or show the web elements, change...
javafx

Getting Started with JavaFX

By Onur Baskirt / Mar 25, 2016 / 0 Comments
When I started to work in my current position, one of my task is to do manual operations for campaign products  every week. After the second week, I thought that I have to automate this task using a GUI based...
extentreports

How to Write Smart XPath Locators

By Onur Baskirt / Sep 24, 2017 / 4 Comments
Hi all, in this tutorial, I will describe you how to write smart and non-brittle XPath locators. When we write our test scripts, we generally prefer to use id, name, class, etc. these kinds of locators. However, sometimes we could not...
extentreports

Selenium-1: Quick Start to Automation with Selenium WebDriver & JAVA & JUnit & Maven & IntelliJ

By Onur Baskirt / Sep 8, 2015 / 26 Comments
Outline Selenium Webdriver is the most popular open source web test automation framework across wide range of browsers and platforms. In this tutorial you will learn how to do web test automation with Selenium Webdriver and the related tools. Audience...
page object model

Page Object Model with C#

By Ege Aksoz / Jun 18, 2017 / 8 Comments
In the previous tutorial, we’ve taken the initial steps and entered the world of automated testing. We also wrote our first automated test. From this point on, since we are not just going to write one test, we need to...
extentreports

How to Select a Date From DatePicker Using Selenium

By Onur Baskirt / Aug 13, 2016 / 6 Comments
When you need to automate a airway, hotel, or similar websites you need to deal with Datepickers and some times it is a little bit cumbersome to select a specific date on the Datepicker or calendar.  In this post, I...
extentreports

Selenium Webdriver Performance testing with Jmeter and Selenium Grid

By Ozgur Kaya / Aug 9, 2016 / 2 Comments
In this post, we will complete Selenium Webdriver Performance testing scenario using Jmeter and Selenium Grid. 1- Install Java 7 or later If necessary https://java.com/tr/download/ 2- Download latest Jmeter version 3.0 or higher. http://jmeter.apache.org/download_jmeter.cgi 3- Download Jmeter PluginsManager JAR file and...
By | 2017-07-24T17:26:02+00:00 July 24th, 2017|Gatling, Performance Testing|0 Comments

About the Author:

Ege Aksoz
Holding a BSc in Mechatronics, Ege loves to automate. He is now working as a Software Test Automation Engineer at Tallinn, Estonia. He is also passionate about Artificial Neural Networks and he is a master student on AI at Tallinn Technical University.

Leave A Comment