Hello all,
I have been working on this problem for over a week. I’m not sure what I am missing, but I’m sure I’ll feel dumb once the solution is brought to light. Basic scenario is I am trying to load test an API. Eventually I will be testing a whole slew of requests, but for now, I just want to get the first two working.
The first request is just a simple login request, which I have been successful with, but the first request elicits a response with a session token. I need to extract this token, and call it in the next JSON request. I have tried utilizing the .saveAs method, but once I get it saved, I cannot call the value of the token anywhere but inside the session. I have tried to find a way to pass the value outside the session to no avail. Please find my script below, and let me know if you have any idea what I have done wrong.
object RunTest {
val login = exec(http(“Begin_Test”)
.post("/Path/To/Request/")
.body(StringBody("""{“logintype”:“user”,
“user”:“user.name”,
“password”:“Summer2017”,
“host”:“111.0.0.10”
}"""))
.transformResponse{
case response if response.isReceived =>
new ResponseWrapper(response) {
val stripped = response.body.string
println("*** stripped = " + stripped)
override val body = new StringResponseBody(stripped, response.charset)
}
}
.asJSON
.check(jsonPath("$…result").is(“true”))
.check(jsonPath("$…session")
.find
.saveAs(“currentSession”)))
val sessionToken = exec(session => {
session(“currentSession”).as[String]
session})
val addUser = exec(http(“Add_User”)
.post("/Path/To/Second/Request/")
.body(StringBody(s"""{“action”:“ADDUSER”,
“controlid”:“ID”,
“session”:"${sessionToken}",
“username”:“UserName”,
“description”:“Test user”,
“fullname”:“John Doe”,
“email":"jdoe@email.com”,
“msg_svc”:"",
“msg_phone”:“8001234567”
}"""))
.asJSON
.check(jsonPath("$…result").is(“true”)))
I have been through a wide variety of errors, but looking at error logs, I see that my main problem is that the session is not getting written correctly. I continually get some gibberish that looks like the code to retrieve the session token. In the Command Prompt, the error I usually get is simply that “false was found where true was expected.”
Any help is appreciated, and thank you very much.
Rob