我有一个包含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
?
答案 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")))`