未在加特林(Gatling)中定义属性

时间:2018-12-26 03:20:43

标签: scala scala-gatling

我有这个模拟文件。 我的想法是创建一个json文件,在json文件中有一些参数。 馈线在加特林中将参数传递给值。 但是问题是当我这样做时,参数没有传递值。

package tci3accountPro

import baseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import tci3accountPro.models.bodyRegisterSubs
import core.api.ApiUtil

import scala.concurrent.duration._

class registerSubscriptions extends BaseSimulation{

  val username = "105C169260"

  val cashAccount = "11111"

  val proCode = "IWEALTH_PRO"
  val typeText = "TRIAL"
  val referrerId105C = "105C310885"

  var ini = new GetTokenApi

  val token = ini.getToken(username)

  val registerSubs = http.baseUrl(accountProDomain + accountProSubs)
    .header("Authorization", token)
    .header("Content-Type","application/json")


  var feeder =  Iterator.continually(Map(
    "cashAccount" -> cashAccount,
    "code105C" -> username,
    "proCode" -> proCode,
    "type" -> typeText,
    "referrerId105C" -> referrerId105C
  ))

  def registerSub() = {
    feed(feeder)
    exec(http("register Subscriptions")
      .post("")
      .body(ElFileBody("bodies/bodyRegisterSubs.json")).asJson
      .check(status.is(200)))
  }

  val scn = scenario("register Subscriptions")
    .exec(registerSub)

  setUp(scn.inject(atOnceUsers(1),rampUsersPerSec(1) to 5 during (10 seconds)).protocols(registerSubs)).maxDuration(1 minutes)
    .assertions(global.responseTime.max.lt(2000), global.successfulRequests.percent.gt(95))
}

和json文件

{
  "cashAccount": "${cashAccount}",
"code105C": "${code105C}",
"proCode": "${proCode}",
"type": "${type}",
"referrerId105C": "${referrerId105C}"
}

但是运行模拟时,它显示:没有定义属性名称“ cashAccount”。 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

在您的registerSub定义中,您需要链接您的方法-如所写,它只是返回exec,因为这是最后一条语句。

将其更改为...

def registerSub() = {
feed(feeder)
.exec(http("register Subscriptions")
  .post("")
  .body(ElFileBody("bodies/bodyRegisterSubs.json")).asJson
  .check(status.is(200)))

}