使用'checkIf'验证时,无法在Gatling会话中保存变量

时间:2017-11-23 17:01:08

标签: scala gatling scala-gatling

我有一个包含2个可能响应的API。

我有以下HTTP构建器:

http("HelloTest")
.post(host + "/hello")
.headers(someHeader)
.body(StringBody(requestPayload))
.check(status.saveAs("responseStatus"))

.check(checkIf((response: Response, session: Session) => session("responseStatus").as[String] == "202")(jsonPath("$.error") is "Waiting for Response"))

.check(checkIf((response: Response, session: Session) => session("responseStatus").as[String] == "200")(jsonPath("$.foo").saveAs("fooVar")))
.check(checkIf((response: Response, session: Session) => session("responseStatus").as[String] == "200")(jsonPath("$").saveAs("responseBodyVar")))`

当我尝试访问会话变量${fooVar}${responseBodyVar}时,我看到一条错误,指出它们未定义。

如何在下一个exec

中提取会话变量

1 个答案:

答案 0 :(得分:1)

我弄清楚了请求中的错误。

代码应如下所示:

http("HelloTest")
.post(host + "/hello")
.headers(someHeader)
.body(StringBody(requestPayload))
.check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == "202")(jsonPath("$.error") is "Waiting for Response"))
.check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == "200")(jsonPath("$.foo").saveAs("fooVar")))
.check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == "200")(jsonPath("$").saveAs("responseBodyVar")))`