【问题标题】:Gatling :- Read Multiple JSON Payload from single fileGatling :- 从单个文件中读取多个 JSON 有效负载
【发布时间】:2016-08-12 05:41:17
【问题描述】:

我正在使用 JSON Payload 发出许多 HTTP 请求,并且我正在为每个请求读取一个文件以获取 JSON Payload,如下所示。

  postPayload1 = val postPayload = ElFileBody("Test_case1.json")

  val TC1 = feed(accountNumberFeeder1)
    .exec(http(testCase1).post(appendPathToUrl).headers(common_header).body(postPayload).asJSON
    .check(status.is(200)
    )

但是,它现在在我的资源目录中变成了如此多的 JSON 文件。那么我可以将我所有的 JSON 合并到一个文件中,如下所示。

{"testCase1":{
  "activationSource": "HH",
  "accountStatus": null,
}
}

{"testCase2":{
  "activationSource": "HH",
  "accountStatus": null,
}
}

并使用我的密钥“testCase1”、“testCase2”等访问它?

val postPayload = ElFileBody("Test_case.json")

【问题讨论】:

    标签: java scala scala-collections gatling


    【解决方案1】:

    从官方 Gatling 文档中,我找到了http://gatling.io/docs/2.2.1/session/feeder.html

    JSON 馈送器 有些人可能希望使用 JSON 格式的数据而不是 CSV:

    val jsonFileFeeder = jsonFile("foo.json")
    val jsonUrlFeeder = jsonUrl("http://me.com/foo.json")
    

    例如,以下 JSON:

    [
      {
        "id":19434,
        "foo":1
      },
      {
        "id":19435,
        "foo":2
      }
    ]
    

    将变成:

    record1: Map("id" -> 19434, "foo" -> 1)
    record2: Map("id" -> 19435, "foo" -> 2)
    

    请注意,根元素当然必须是一个数组。

    【讨论】:

      猜你喜欢
      • 2020-04-28
      • 1970-01-01
      • 2021-12-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 2016-08-18
      • 2019-02-21
      • 2021-01-19
      相关资源
      最近更新 更多