Reputation: 599
I have an API with 2 possible responses.
I have the below HTTP builder:
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")))`
When I try to access the session variables ${fooVar}
and ${responseBodyVar}
, I see an error stating they are not defined.
How can I extract the session variables in the next exec
?
Upvotes: 1
Views: 1091
Reputation: 599
I figured out what was wrong in the request.
The code should look like this:
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")))`
Upvotes: 1