In the following code snippet, if “_id” is not found in the http response then i get an exception
.check(jsonPath("$._id").find.saveAs(idVarName))
The exception is
jsonPath($._id).find.exists preparation crashed: Jackson failed to parse into a valid AST: c.f.j.d.e.MismatchedInputExceptio…
How can i control this check so that if i get a 401 from the server, this check is skipped and hence the exception is not generated?
Hi,
Did you find a fix? Actually i’m also facing the same issue where getting a 401 from the server is causing Json path errors because the response has the following body-
<html><head><title>Error</title></head><body>Token is not Valid</body></html>
Is there any way where i can skip the jsonpath check whenever 401 occurs?
First perform a check that saves the status, then perform a conditional check that only triggers when the saved status is not 401.
hi @slandelle ,
Thanks for the info. i actually applied the conditional checks that whenever response code is 200 only then json extractions should happen. but somehow the multiple json extractions are not happening in this case. Maybe something wrong with my syntax can you check? my implementation is as follows-
val test: ChainBuilder = exec(http("test url")
.get("test url")
.headers(headers_1)
.check(status.saveAs("responseCode"))
.check(status.in(200, 401))
.check(checkIf((response: Response, session : Session) => response.status.code == 200) {
jsonPath("$[?(@.fullAccess==true)].id").optional.saveAs("test1")
jsonPath("$..id").optional.saveAs("test2")
jsonPath("$[-1:].name").optional.saveAs("test3")
}
)
)
It should work, even if I’d rather write if this way:
val test = exec(http("test url")
.get("test url")
.check(status.in(200, 401).saveAs("responseCode"))
.checkIf(session => session("responseCode").as[Int] == 200) {
jsonPath("$[?(@.fullAccess==true)].id").optional.saveAs("test1")
jsonPath("$..id").optional.saveAs("test2")
jsonPath("$[-1:].name").optional.saveAs("test3")
}
)
If it doesn’t work, please provide a reproducer as instructed here: How to Ask a Question - #2.
Hi @slandelle ,
I tried with your syntax but it gives the following compilation error:-
value checkIf is not a member of io.gatling.http.request.builder.HttpRequestBuilder
[ERROR] possible cause: maybe a semicolon is missing before `value checkIf’?
I also tried with this syntax:-
val test = exec(http(“test url”)
.get(“test url”)
.check(status.in(200, 401).saveAs(“responseCode”))
.check(checkIf(session => session(“responseCode”).as[Int] == 200) {
jsonPath("$[?(@.fullAccess==true)].id").optional.saveAs(“test1”)},
{jsonPath("$…id").optional.saveAs(“test2”)},
{ jsonPath("$[-1:].name").optional.saveAs(“test3”)}
)
)
It gets compiled and the multiple json extractions are successful but the checkif statement only gets applied to the first json extraction & not for all.
So can you provide any way/syntax to get multiple json extractions under one checkif statement so that i don’t have to write them again and again for all json extractions?
***Just FYI my gatling version is 3.2.0
Just FYI my gatling version is 3.2.0
That’s your issue. The first thing to do is to upgrade from your version from 3 years ago!