Getting Gatling

Gatling can be downloaded here and typically you can start Gatling using the gatling.bat or gatling.sh scripts located in the downloaded archive bin directory. To prepare your first test plan you may find the Gatling recorder useful.

Creating a Test Plan

Once you have created or downloaded our basic test plan and saved it locally as a .scala file, you can upload this to Tricentis Flood to create your first Flood test.

To make sure your Gatling test plan is compatible with Flood you need to import the Flood libraries as follows:

// Mandatory, you must import Flood libraries
import flood._

You also need to make sure your httpProtocol uses the predefined httpConfigFlood element as follows:

// Mandatory, you must use httpConfigFlood
val httpProtocol = httpConfigFlood
    .baseURL("http://google.com/")
    .acceptHeader("text/html,application/xhtml+xml,application/xml;")
    .acceptEncodingHeader("gzip, deflate")

This helps uniquely identify your tests on Flood and makes use of custom Flood libraries for detailed reporting and transaction tracing.

Note: If you want to develop scripts locally you can stub Tricentis Flood libraries by downloading flood.scala. However, don't upload this file when using Flood.

Basic Example Test Plan

The complete script should look like this:

import scala.concurrent.duration._

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

// Mandatory, you must import Flood libraries
import flood._

class TestPlan extends Simulation {
  // Optional, Flood will pass in threads, rampup and duration properties from UI
  val threads   = Integer.getInteger("threads",  100)
  val rampup    = java.lang.Long.getLong("rampup", 30L)
  val duration  = java.lang.Long.getLong("duration", 300L)

  // Mandatory, you must use httpConfigFlood
  val httpProtocol = httpConfigFlood
    .baseURL("https://flooded.io/")
    .acceptHeader("text/html,application/xhtml+xml,application/xml;")
    .acceptEncodingHeader("gzip, deflate")

  val myScenario = scenario("Scenario Name")
    .during(duration seconds) {
      exec(http("home_page")
      .get("/"))
      .pause(1000 milliseconds, 5000 milliseconds)
    }

  setUp(myScenario.inject(rampUsers(threads) over (rampup seconds))).protocols(httpProtocol)
}

Creating a Flood Test

After you login to Flood you can click the "+" icon or from your Floods dashboard you can click the "New Flood" button to create a new Flood.

In the new Flood form, add the .scala test plan you created using Gatling to the Files input and select a Grid to run your Flood test on. You can optionally set the "Name" or "Tags" to help identify the test in your dashboard.

Start your Flood Test

Read about more [advanced settings] or simply click the "Launch Flood" button to launch your test.

You will be redirected to a Flood report which will show you results in real time from the test you just executed on the chosen Grid.

Advanced Simulations

As you progress you may find you are developing more advanced simulations for Gatling. This may include elements such as page objects, request bodies, dynamic data feeders for CSV and the like. As a result your user-simulations directory may have multiple sub directories. The best way for Flood to replicate this structure is for you to upload a compressed zip archive of the directory along with a simulation suited for Flood which exercises your intended scenarios.

For example your local directory structure may look like this:

user-files
├── bodies
├── data
│   └── search.csv
├── page-objects
│   ├── home.scala
│   └── search.scala
└── simulations
    └── MyLoadTest.scala

Simply create a zip archive of the directory user-files and upload that with an additional simulation (separate to the zip archive) that calls your scenarios.

For example:

import scala.concurrent.duration._

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

// Mandatory, you must import Flood libraries
import flood._

class FloodLoadTest extends Simulation {
  // Optional, Flood will pass in threads, rampup and duration properties from UI
  val threads   = Integer.getInteger("threads",  100)
  val rampup    = java.lang.Long.getLong("rampup", 30L)
  val duration  = java.lang.Long.getLong("duration", 300L)

  // Mandatory, you must use httpConfigFlood
  val httpConf = httpConfigFlood.baseURL("https://loadtest.flood.io")

  val myScenario = scenario("scenario")
    .exec(Home.visit)
    .exec(Search.search)
    .pause(1000 milliseconds, 5000 milliseconds)

  setUp(myScenario.inject(rampUsers(threads) over (rampup seconds))).protocols(httpProtocol)
}

Tricentis Flood will then extract files into the destination user-files directory on each of the grid nodes and execute the customised FloodLoadTest simulation within the simulations directory:

user-files
├── bodies
├── data
│   └── search.csv
└── simulations
     ├── page-objects
     │   ├── home.scala
     │   └── search.scala
     └── MyLoadTest.scala
     └── FloodLoadTest.scala

You can find example code for this advanced simulation here.

Did this answer your question?