【问题标题】:How to pass the value from JsonPath( Session Attribute) to PebbleStringBody in Gatling with Scala如何使用 Scala 在 Gatling 中将 JsonPath(Session Attribute) 的值传递给 PebbleStringBody
【发布时间】:2022-10-17 00:26:24
【问题描述】:

如何传递值JsonPath(会话属性)PebbleStringBody加特林斯卡拉.

    .exec(http("Find PerfTest")
      .get("/PerfTest")
      .queryParam("TesterID", Tester)
      .check(jsonPath("$.results[*].name").findAll.saveAs("name"))
      .check(jsonPath("$.results[*].id").findAll.saveAs("TestID"))
      .check(jsonPath("$.total").find.saveAs("Totalperfcount"))
    )

    .exec(http("PerfTest")
      .post("/PerfTest/bulk")
      .body(PebbleStringBody(
       """| [
          | {% for t in range(1,({{Totalperfcount}}).toInt) %} //cannot get the value from Jsonpath(Session Attribute)
          |    {
          |   "name": "{{name}}", //cannot get the value from Jsonpath(SessionAttribute)
          |   "TestID": "{{TestID}}", //cannot get the value from Jsonpath(SessionAttribute)
          |    }
          |  {% if loop.last %}
          |  {% else %},{% endif %}
          |  {% endfor %}
          |  ]""".stripMargin)).asJson
      .check(status.is(200))
    )

输出错误:

build ERROR io.gatling.http.action.HttpRequestAction - 'httpRequest-1' failed to execute: Unexpected token of value "}" and type PUNCTUATION,
 expected token of type PUNCTUATION ([ {% for t in range(1,({{Totalperfcount}}).toInt) %} { "name": "{{name}}",, "TestID": "{{TestID}}", "value": {} } {% if loop.last %} {% else %},{% endif %} {% endfor %} ]:2) 23:14:37.707 [gatling-1-2] 
DEBUG io.gatling.core.action.Exit

我可以使用任何特定的方法吗?请帮我解决问题

【问题讨论】:

  • 你正在做的事情应该是有效的。请注意nameTestID 是列表,因为您使用的是saveAs。我建议你启用跟踪日志来调试你的问题,并提供一个重现器。
  • 不,它不工作。我总是收到错误。由于响应未得到构建错误 io.gatling.http.action.HttpRequestAction - 'httpRequest-1' 未能执行:值“}”的意外令牌和 PUNCTUATION 类型,预期的 PUNCTUATION 类型令牌([ {% for t in range(1,({{Totalperfcount}}).toInt) %} { "name": "{{name}}",, "TestID": "{{TestID}}", "value": {} } { % if loop.last %} {% else %},{% endif %} {% endfor %} ]:2) 23:14:37.707 [gatling-1-2] DEBUG io.gatling.core.action.Exit
  • 那么这与加特林无关。您的 pebble 模板中有语法错误。最好创建一个仅标记为 pebble 的问题,以避免混淆。

标签: scala performance-testing gatling scala-gatling pebble


【解决方案1】:

我试过这个

问题出在 for 循环中,而且这也不支持对 pebble 字符串的 List 或 Array 调用。

你最终会得到Vector(Value 1,....ValueN)

你的例子

[
 {
     "name": "Name1,.,.....Name N
     "TestID": "TestID1234,.,....TestIDnnnn"
 }
]

这将给出错误状态 400。

我来这里是为了寻找答案,因为我正在寻找与 Gatling 类似的场景。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 2016-10-26
    • 2020-10-22
    相关资源
    最近更新 更多