Gatling 2 - 将值映射到模板

时间:2014-01-15 16:36:50

标签: scala gatling

我正在考虑转移到Gatling 2.0.0-M3a,但我遇到了基本测试工作的问题。我遇到的问题是将值映射到Gatling 2中的模板文件。下面的示例显示了我是如何在Gatling 1.5中实现的,但我无法在2中找到它。

LoginScenario.scala - 适用于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 - 错误 - 重写版本以适应Gatling 1.5和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 - 两个示例中使用的模板

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

2 个答案:

答案 0 :(得分:3)

我们在Gatling 2中放弃了Scalate,因为它非常麻烦。

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

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

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

loginTemplate.txt:

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

答案 1 :(得分:2)

ElFileBody不是ELFileBody。检查案例