【问题标题】:Gatling 2 - Mapping values to templateGatling 2 - 将值映射到模板
【发布时间】:2014-02-04 06:08:21
【问题描述】:

我正在考虑迁移到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",
  }
}

【问题讨论】:

    标签: scala gatling


    【解决方案1】:

    它是ElFileBody 而不是ELFileBody。检查案例

    【讨论】:

      【解决方案2】:

      我们在 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",
        }
      }
      

      【讨论】:

      • 我们可以使用.body(ELFileBody("request-bodies/loginTemplate.json")),而不是.txt格式吗?
      • 像 ${id} 这样的值需要在会话中。一种方法是执行 .exec(_.set("id", UUID.randomUUID()))
      • 从 2.2 开始是 ElFileBody
      猜你喜欢
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-14
      相关资源
      最近更新 更多