【发布时间】: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
我可以使用任何特定的方法吗?请帮我解决问题
【问题讨论】:
-
你正在做的事情应该是有效的。请注意
name和TestID是列表,因为您使用的是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