3

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",
  }
}
4

2 回答 2

6

我们在 Gatling 2 中放弃了 Scalate,因为它真的很麻烦。

请查看我们的 wiki 以了解新语法:https ://github.com/excilys/gatling/wiki/Gatling-2#wiki-bodies

基本上,您可以在模板中编写常规的 Gatling EL,并且不再需要显式传递参数:

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

登录模板.txt:

{
  "userName": "${userName}",
  "password": "${password}",
  "platformCode": "app",
  "clientInformation": {
    "operatingSystem": "OSX",
    "operatingSystemVersion": "10.8",
    "browser": "Chrome",
    "browserVersion": "31",
  }
}
于 2014-01-15T17:05:04.157 回答
5

ElFileBody不是ELFileBody。检查案例

于 2018-03-07T04:28:22.723 回答