Modularising scenarios to run in sequence using Gatling

Mark Baker picture Mark Baker · Mar 22, 2013 · Viewed 26k times · Source

I'm trying to modularise a series of performance tests in Gatling.

Several of the tests execute the same initial path through the pages, so I thought that I could break them down into a series of scenarios, each scenario being a series of shared actions defined in its own file, and then a final Simulation definition that simply executed the specified scenarios one after the other.

What I then need is for my Simulation to run those scenarios in sequence; but I can only find how to run them either concurrently, or with a specified delay between each. Is there any Simulation setup option to run the defined scenarios one after the other without specifying an arbitrary delay?

EDIT

Currently, I have the following set of files:

homepageHeaders.scala

package advanced

object homepageHeaders {

    val homepage_headers_1 = Map(
        "Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""",
        "If-Modified-Since" -> """Wed, 20 Mar 2013 15:36:31 +0000""",
        "If-None-Match" -> """"1363793791""""
    )

}

homepageChain.scala

package advanced
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import akka.util.duration._
import homepageHeaders._


object homepageChain {

    val homepageChain = 
        //Homepage
        exec(http("homepage")
                    .get("/")
                    .headers(homepageHeaders.homepage_headers_1)
            )

}

pageHeaders.scala

package advanced

object pageHeaders {

    val page_headers_1 = Map(
            "Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"""
    )

}

pageChain.scala

package advanced
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import akka.util.duration._
import pageHeaders._


object pageChain {

    val pageChain = 
        //Page Menu
        exec(http("page request")
                    .get("/page1")
                    .headers(pageHeaders.page_headers_1)
            )

}

pageSimulation.scala

package advanced
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import homepageChain._
import pageChain._

class pageSimulation extends Simulation {

    val urlBase = "http://www.mytestsite.com"

    val httpConf = httpConfig
            .baseURL(urlBase)
            .acceptHeader("image/png,image/*;q=0.8,*/*;q=0.5")
            .acceptEncodingHeader("gzip, deflate")
            .acceptLanguageHeader("en-gb,en;q=0.5")
            .userAgentHeader("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0")

    val pageScenario = scenario("Bodycare Scenario")
        .exec(homepageChain.homepageChain)
        .exec(pageChain.pageChain)


    setUp(
            homepageScenario.users(1).protocolConfig(httpConf)
        )
}

The error that I'm getting is:

14:40:50.800 [ERROR] c.e.e.g.a.ZincCompiler$ - /Gatling/user-files/simulations/advanced/pageChain.scala:13: not found: value exec
14:40:50.807 [ERROR] c.e.e.g.a.ZincCompiler$ -          exec(http("page request")
14:40:50.808 [ERROR] c.e.e.g.a.ZincCompiler$ -          ^
14:40:53.988 [ERROR] c.e.e.g.a.ZincCompiler$ - /Gatling/user-files/simulations/advanced/homepageChain.scala:13: not found: value exec
14:40:53.989 [ERROR] c.e.e.g.a.ZincCompiler$ -          exec(http("homepage")
14:40:53.989 [ERROR] c.e.e.g.a.ZincCompiler$ -          ^
14:41:17.274 [ERROR] c.e.e.g.a.ZincCompiler$ - two errors found
Exception in thread "main" Compilation failed

Clearly I'm missing something in my definition, but I just don't understand what it is

Answer

Stephane Landelle picture Stephane Landelle · Mar 22, 2013

You can compose chains, not scenarios.

For example:

val login = exec(...)...
val foo = exec(...)...
val bar = exec(...)...
val scn1 = scenario("Scenario1").exec(login).exec(foo)
val scn2 = scenario("Scenario2").exec(login).exec(bar)

Clear?