Phi Nguyen is a QA engineer with 11+ years of experience . His areas of experience include manual testing, automation testing, acceptance testing, regression testing, database testing, API testing and web/mobile apps testing. He currently works full time as a freelancer.

Learn JMeter in 5 Hours

Start Learning
Slack

Run massively scalable performance tests on web, mobile, and APIs

May 23 2018

How to Run a Simple Load Test with Gatling

Gatling is a load and stress testing tool based on Scala and built for high performance. This blog post will explain how to run a simple load test in Gatling.  We will load test the following test case:

 

  1. Open the Browser and go to the site http://www.demoblaze.com.
  2. Click on the text “Cart”.

 

running a gatling load test

 

Configure Your Browser

 

We will record the scenario we want to test. To do that, we need to configure our browser proxy settings at first. The following steps will show you how to configure the Chrome browser for a Gatling recording.

 

1. Open the Chrome Browser.

 

2. Click on the Customize and control Google chrome button located at the top right corner. A drop down menu will be displayed.

 

gatling test tutorial

 

3. Click on the Settings option.

 

gatling explanation

 

4. Scroll down to the bottom of the page and click on Advanced to expand the page.

 

how to run a gatling load test

 

5. Click on Open proxy settings.

 

running a gatling performance test

 

6. In the Internet Properties window, click on the Connections tab.

 

7. Click on the LAN Settings button.

 

gatling load testing tutorial

 

8. In the LAN Settings window:

  • Uncheck Automatically detect settings.
  • Check Use as proxy server for your LAN.
  • Type the address 127.0.0.1 and the port 8080.
  • Click OK.

 

running open source gatling

 

9. Click the OK button in the Internet Options window.
 

10. Close the browser window.
 

In other browsers similar steps can be followed.

 

Recording the Scenario

 

11. Make sure you have Gatling installed on your computer.

 

12. Go to the bin folder (in my case: C:\gatling-charts-highcharts-bundle-2.3.1\bin) of the Gatling bundle.

 

13. Double click on the recorder.bat file.

 

ultimate guide for gatling scripting

 

14. A command prompt window will be displayed.

 

using gatling for your performance testing

 

15. A recorder window will be automatically displayed. This is the default:

 

gatling script recording

 

16. In the recorder window change the settings:

  • Enter the port number in the local host box (In my case 8080).
  • Enter the Package name as blazemeter. You can choose the name you prefer.
  • Enter class name as BlazemeterPricing. You can choose the name you prefer.
  • Check the Follow Redirects?, Infer HTML resources?, Remove cache Headers? and Automatic Referers? options.
  • Select the output files path. In my case (C:\gatling-charts-highcharts-bundle-2.3.1\user-files\simulations). This path is where the script will be stored after recording. You can change the location but if you do, don’t forget to copy it to the Gatling simulations folder. To make things easy, it’s recommended to leave the path as default.
  • Keep all the other options the same. Don’t change any existing options.
  • Click on the Start button.

 

open source load testing with gatling

 

17. Open the Google chrome browser.

 

18. Go to the URL: http://www.demoblaze.com.

 

step by step gatling load testing

 

19. In the DemoBlaze page, click on the link text “Cart”.

 

gatling framework testing guide

 

20. Close the browser.

 

21. Click on the Stop & Save button in the Gatling recorder window and it will close.

 

how do i get started with gatling

 

22. A recorder file named BlazemeterPricing.scala is created and saved to the “C:\gatling-charts-highcharts-bundle-2.3.1\user-files\simulations\blazemeter” directory. This scala script is automatically created after recording.
 

Note that the file name is the class name with the extension .scala and it is located in a folder named “blazemeter” that is the same as the package name that we entered in the recorder window. This folder structure should be followed for load testing.

 

gatling help

 

Configuring the Gatling Script

 

23. Below is the script file written in the Scala programming language. We can configure the number of users and how they are run in the script. We can also add a global pause, add assertions and configure HTTP or HTTPS protocols through this script. We will not go into great detail about script configuration here, only provide a few examples. To learn about script configuration, go here.

 

The setUp() method is used to configure the user. In the example below it is configured for 1 user and use the HTTP protocol for load testing: setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)

 

 
package blazemeter

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class BlazemeterPricing extends Simulation {

	val httpProtocol = http
		.baseURL("http://www.demoblaze.com")
		.inferHtmlResources()
		.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
		.acceptEncodingHeader("gzip, deflate")
		.acceptLanguageHeader("vi,en-US;q=0.9,en;q=0.8")
		.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")

	val headers_0 = Map("Upgrade-Insecure-Requests" -> "1")

	val headers_1 = Map(
		"Accept" -> "*/*",
		"Origin" -> "http://www.demoblaze.com")

	val headers_2 = Map("Accept" -> "image/webp,image/apng,image/*,*/*;q=0.8")

    val uri1 = "https://ajax.googleapis.com/ajax/libs/jquery"
    val uri2 = "https://unpkg.com"
    val uri3 = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"

	val scn = scenario("BlazemeterPricing")
		.exec(http("request_0")
			.get("/")
			.headers(headers_0)
			.resources(http("request_1")
			.get("/css/fonts/Lato-Regular.woff2")
			.headers(headers_1),
            http("request_2")
			.get("/imgs/front.jpg")
			.headers(headers_2)))
		.pause(8)
		.exec(http("request_3")
			.get("/cart.html")
			.headers(headers_0))

	setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
	
}

 

Executing a Load Test with Gatling

 

24. Go to the bin folder (in my case: C:\gatling-charts-highcharts-bundle-2.3.1\bin).

 

25. Double click on the gatling.bat file. This is the Gatling execution file, which runs the test, in this case: BlazemeterPricing.scala.

 

gatling load testing help

 

26. A command prompt window is displayed and then load testing information is displayed on the command prompt window such as: GATLING_HOME variable, Java execution file, Scripts in simulations directory.

 

27. The Command prompt window will look like this:

 

gatling performance testing help

 

28. Since there is only one simulation file the default simulation id is “BlazemeterPricing”. So enter this name and press the Enter key.

 

gatling performance testing tutorial

 

29. After pressing the Enter key from the keyboard, the window will look like the following. It asks for an optional run description.

 

gatling performance testing uide

 

30. In most cases the run description will be the objective or title of the test cases, and also the number of users and load description. The description is intended to explain the goal of the load test to anyone reading this description. This is an optional step, you can skip it by pressing "Enter".

 

In my case, “Browse to demoblaze page. Number of User : 1”. Now, press the Enter key.

 

gatling script description

 

31. After pressing the Enter key the simulation starts.

 

gatling test simulation

 

32. When the simulation is complete you will see a link that generates the report in HTML format.

 

gatling load test demo

 

33. Copy the report path and press the Enter key to close the command prompt window.

 

34. Go to the result path (In my case: C:\gatling-charts-highcharts-bundle-2.3.1\results\blazemeterpricing-1525076397702) and you will see the HTML file.

 

gatling result path

 

35. Double click the index.html file to open the report in a chrome browser.

 

gatling reporting

 

reading gatling reports

 

Load Testing with Different Scenarios

 

Load testing with 10 users added over 5 seconds (1 extra user every 500 ms)

 

36. go to the setUp() method and customize it: setUp(scn.inject(rampUsers(10) over (5 seconds))).protocols(httpProtocol).

 

This defines load testing with 10 users added over 5 seconds (1 extra user every 500 ms) with the http protocol.

 

The result:


 
package blazemeter

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class BlazemeterPricing extends Simulation {

	val httpProtocol = http
		.baseURL("http://www.demoblaze.com")
		.inferHtmlResources()
		.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
		.acceptEncodingHeader("gzip, deflate")
		.acceptLanguageHeader("vi,en-US;q=0.9,en;q=0.8")
		.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")

	val headers_0 = Map("Upgrade-Insecure-Requests" -> "1")

	val headers_1 = Map(
		"Accept" -> "*/*",
		"Origin" -> "http://www.demoblaze.com")

	val headers_2 = Map("Accept" -> "image/webp,image/apng,image/*,*/*;q=0.8")

    val uri1 = "https://ajax.googleapis.com/ajax/libs/jquery"
    val uri2 = "https://unpkg.com"
    val uri3 = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"

	val scn = scenario("BlazemeterPricing")
		.exec(http("request_0")
			.get("/")
			.headers(headers_0)
			.resources(http("request_1")
			.get("/css/fonts/Lato-Regular.woff2")
			.headers(headers_1),
            http("request_2")
			.get("/imgs/front.jpg")
			.headers(headers_2)))
		.pause(8)
		.exec(http("request_3")
			.get("/cart.html")
			.headers(headers_0))

	setUp(scn.inject(rampUsers(10) over (5 seconds))).protocols(httpProtocol)
	
}

 

 

gatling load testing kpis

 

gatling performance testing kpis

 

Load testing with 10 concurrent users

 

37. Got to the setUp() method and configure it: setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol).

 

This defines load testing with 10 concurrent users with the http protocol.

 

The result:

package blazemeter

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class BlazemeterPricing extends Simulation {

	val httpProtocol = http
		.baseURL("http://www.demoblaze.com")
		.inferHtmlResources()
		.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
		.acceptEncodingHeader("gzip, deflate")
		.acceptLanguageHeader("vi,en-US;q=0.9,en;q=0.8")
		.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36")

	val headers_0 = Map("Upgrade-Insecure-Requests" -> "1")

	val headers_1 = Map(
		"Accept" -> "*/*",
		"Origin" -> "http://www.demoblaze.com")

	val headers_2 = Map("Accept" -> "image/webp,image/apng,image/*,*/*;q=0.8")

    val uri1 = "https://ajax.googleapis.com/ajax/libs/jquery"
    val uri2 = "https://unpkg.com"
    val uri3 = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"

	val scn = scenario("BlazemeterPricing")
		.exec(http("request_0")
			.get("/")
			.headers(headers_0)
			.resources(http("request_1")
			.get("/css/fonts/Lato-Regular.woff2")
			.headers(headers_1),
            http("request_2")
			.get("/imgs/front.jpg")
			.headers(headers_2)))
		.pause(8)
		.exec(http("request_3")
			.get("/cart.html")
			.headers(headers_0))

	setUp(scn.inject(atOnceUsers(10))).protocols(httpProtocol)
	
}

 

gatling load testing results

 

analyzing gatling performance testing results

 

Running your Gatling Load test with BlazeMeter

 

After recording you Gatling file, you can also run it through BlazeMeter. Just go to BlazeMeter and choose “Taurus Test”. In BlazeMeter you will be able to scale your tests for as many users as you need, and run it from all over the world through the cloud.

 

In BlazeMeter you will also be able to share your tests and results with co-workers and managers, and analyse results in real-time or over time in insightful reports.

 

running gatling with blazemeter

 

Enjoy your load testing with Gatling! To get started with BlazeMeter, request a demo, or put your URL in the box below and your test will start in minutes.

 

gatling, blazemeter, taurus, open source, cloud, scaling

Interested in writing for our Blog?Send us a pitch!

Your email is required to complete the test. If you proceed, your test will be aborted.