Reading list Switch to dark mode

    Gatling Simulation Structure

    Updated 29 January 2020

    Gatling is a Scala based load testing tool. All the scripts which are written & executed via this testing tool, are known as Gatling Simulations. Gatling Simulations are written in Scala language, but there is no hassles of learning the Scala language in deep as Gatling comes up with the Scala Recorder which records all the different scenarios & responsible for generating those scenarios into Gatling Simulation.

    Scala Recorder generates the Gatling Simulation & stores at the path– /gatling-charts-highcharts-bundle-3.1.2/user-files/simulations with .scala extension under the Gatling package. After the execution of the Gatling Simulation, it generates the .class file under path– /gatling-charts-highcharts-bundle-3.1.2/target/test-classes which can be run at any Operating System.

    Gatling Simulation Structure:

    Gatling Simulation contains package name, imports the different class files & extends the Gatling Class “Simulation”, contains the header information, scenarios in the form of series of requests & load test simulation setup.

    A Gatling Simulation example is shown below:

    package basicgatling
    import scala.concurrent.duration._
    import io.gatling.core.Predef._
    import io.gatling.http.Predef._
    import io.gatling.jdbc.Predef._
    
    class scriptbasic extends Simulation {
    	val httpProtocol = http
    		.baseUrl("http://vrindasharma.com")
    		.inferHtmlResources()
    		.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    		.acceptEncodingHeader("gzip, deflate")
    		.acceptLanguageHeader("en-US,en;q=0.5")
    		.userAgentHeader("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0")
    
    	val headers_0 = Map("Upgrade-Insecure-Requests" -> "1")
    	val headers_1 = Map(
    		"Accept" -> "application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8",
    		"Accept-Encoding" -> "identity")
    	val scn = scenario("scriptbasic")
    		.exec(http("request_0")
    			.get("/d8/")
    			.headers(headers_0)
    			.resources(http("request_1")
    			.get("/catalog/view/javascript/font-awesome/fonts/fontawesome-webfont.woff2?v=4.4.0")
    			.headers(headers_1)))
    		.pause(2)
    		.exec(http("request_2")
    			.get("/index.php?route=product/category&path=25_28")
    			.headers(headers_0))
    	setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
    }

    Gatling Simulation Script can be partitioned into four sections i.e

    Start your headless eCommerce
    now.
    Find out More
    • HTTP Protocol Configuration
    • Header Definition
    • Scenario Definition
    • Simulation Definition
    1. HTTP Protocol Configuration: It defines the base URL for which the Gatling Simulation is generated.
    val httpProtocol = http
    		.baseUrl("http://vrindasharma.com")
    		.inferHtmlResources()
    			.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
    			.acceptEncodingHeader("gzip, deflate")
    		        .acceptLanguageHeader("en-US,en;q=0.5")
    		        .userAgentHeader("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0")

    2. Header Definition: It defines the header which is sent along with the base URL.

    val headers_0 = Map("Upgrade-Insecure-Requests" -> "1")
    
    	val headers_1 = Map(
    		"Accept" -> "application/font-woff2;q=1.0,application/font-woff;q=0.9,*/*;q=0.8",
    		"Accept-Encoding" -> "identity")

    3. Scenario Definition: This is the actual scenario which is being performed. A scenario consists of the series of requests.

    val scn = scenario("scriptbasic")
    		.exec(http("request_0")
    		.get("/d8/")
    		.headers(headers_0)
    		.resources(http("request_1")
    		.get("/catalog/view/javascript/font-awesome/fonts/fontawesome-webfont.woff2?v=4.4.0")
    			.headers(headers_1)))
    		.pause(2)
    		.exec(http("request_2")
    		.get("/index.php?route=product/category&path=25_28")
    		.headers(headers_0))

    Here, a value “scn” is declared & assign it a “scenario” named it as “scriptbasic”. A .exec() method is called to send the http requests. A .get() method is used to send the endpoint call to the base URL like http://vrindasharma.com/d8/index.php?route=product/category&path=25_28.

    .pause() method is used to calculate the pause in seconds between the two successive http requests.

    4. Simulation Definition: It defines the load injected to the server in terms of different parameters like number of users at once, ramp, duration etc.

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

    The above section defines the number of users injected(.inject() method) for the particular scenario(value scn) along with the header(value httpconf). It uses the .protocols() method to pass the header information to every request.

    The above explained part is the very basic script to understand the Gatling Simulation Structure.

    In case you have any queries then feel free to ask in the comment section below.

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home