1

我有一个带有 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

4

1 回答 1

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")))`
于 2017-11-27T10:22:43.270 回答