Question

I am considering moving to Gatling 2.0.0-M3a, but I am having issues getting a basic test working. The issue I am having is mapping values to a template file in Gatling 2. The examples below show how I achieved this in Gatling 1.5, but I can't figure it out in 2.

LoginScenario.scala - works in gatling 1.5

package StressTesting

import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import Headers._
import akka.util.duration._
import bootstrap._

object LoginScenario {

    val scn = scenario("Login")
        .feed(csv("user_credentials.csv"))
        .exec(
            http("login")
                .post("/api/login")
                .fileBody("loginTemplate",
                    Map(
                        "userName" -> "${userName}",
                        "password" -> "${password}"
                        )
                    ).asJSON
                .headers(post_header)
                .check(status.is(200)))
    }

LoginScenario.scala - ERRORS - Reworked version to accommodate changes between Gatling 1.5 and 2

package StressTesting

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import Headers._
import scala.concurrent.duration._
import bootstrap._
import io.gatling.core.session.Expression

object LoginScenario {

  val scn = scenario("Login")
    .feed(csv("user_credentials.csv"))
    .exec(
      http("login")
        .post("/api/login")
            .body(ELFileBody("request-bodies/loginTemplate.ssp", 
        Map("userName" -> "${userName}","password" -> "${password}"))).asJSON
        .headers(post_header)
        .check(status.is(200))
    )
}

loginTemplate.ssp - Template used in both examples

{
  "userName": "<%= userName %>",
  "password": "<%= password %>",
  "platformCode": "app",
  "clientInformation": {
    "operatingSystem": "OSX",
    "operatingSystemVersion": "10.8",
    "browser": "Chrome",
    "browserVersion": "31",
  }
}
Was it helpful?

Solution

We've dropped Scalate in Gatling 2, as it was really cumbersome.

Please have a look at our wiki for the new syntax: https://github.com/excilys/gatling/wiki/Gatling-2#wiki-bodies

Basically, you can write regular Gatling EL in you template, and you no longer have to explicitly pass parameters:

.body(ELFileBody("request-bodies/loginTemplate.txt"))

loginTemplate.txt:

{
  "userName": "${userName}",
  "password": "${password}",
  "platformCode": "app",
  "clientInformation": {
    "operatingSystem": "OSX",
    "operatingSystemVersion": "10.8",
    "browser": "Chrome",
    "browserVersion": "31",
  }
}

OTHER TIPS

It is ElFileBody not ELFileBody. Check the case

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top