Hello,
I’ using gatling 2.1.7 and I’m blocked by a problem…
I have to extract JSON from a request
I’m new in gatling and scala too, that’s why I need some help
val scn = scenario("Go to Accounts UI")
.exec(
http("login")
.post(siteUrl ++ "/j_spring_security_check")
.extraInfoExtractor(
extra =>
List(s" REQUEST:${extra.requestName}", s"KS:${extra.request.getCookies}", s"HEADERS:${extra.request.getHeaders}", s"URL:${extra.request.getUrl}")
)
.basicAuth("user", "administrator")
.check(status.is(200).saveAs("some"))
.check(currentLocation
.transform(s => {
val regex = ("jsessionid=\\w+").r
(regex findFirstIn s).get.split("=").get(1)
})
.saveAs("sid"))
).pause(5)
.feed(utcFeeder)
.feed(feeder)
//.exec(addCookie(Cookie("Set-Cookie", "${sid}")))
.exec(session => {addCookie(Cookie("JSESSIONID", "${sid}"))
session.set("","")})
.exec(http("Search PU")
// .get("/${sid}/")
.get(siteUrl + "/some/url")
.header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
.extraInfoExtractor(extra =>
List(s" RECVEST2:${extra.requestName}", s"KUKUISS2:${extra.request.getCookies}", s"HEDERS2:${extra.request.getHeaders}", s"URILI2:${extra.request.getUrl}")
)
.extraInfoExtractor(
extraInfo =>
List(
extraInfo.requestName,
s"\nGeneral Response:\r\n${extraInfo.response}",
s"\nExists??:\r\n${extraInfo.response.hasResponseBody}",
s"\nResponse Body:\r\n${extraInfo.response.body.string}"
)
)
.body(StringBody( """{"SourceSubscriberIdentifier":"${sourcesubscriberidentifier}"}"""))
.asJSON
.headers(headers_14)
.check(jsonPath("$.success")
.saveAs("myResponse"))
)
.exec(session => {
println(session.get("myResponse"))
session
}
)
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
The result is:
REquEST:login KS:[JSESSIONID=1DC3179CCDADD5503A0CBDB6C170D811; path=/enr/; HTTPOnly] HEADERS: URL:http://localhost:8080/enr/logon/logon.jsp;jsessionid=1DC3179CCDADD5503A0CBDB6C170D811?logon_error=
jsonPath($.success).find(0).exists failed, could not prepare: Could not parse response into a JSON object: Unable to determine the current character, it is not a string, number, array, or object The current character read is '<' with an int value of 60 Unable to determine the current character, it is not a string, number, array, or object line number 4 index number 6 <html> ^
What am I doing wrong that I don't have Acsess
Thank you!