Having Problems with saveAs

Hi everyone, im new to Gatling and can’t figure out how to get “saveAs” to work the way i want.
I’m trying to save variables form one response and use them in the next request.

`
import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class demo extends Simulation {

var idToken = “”
var clientID = “”

val httpProtocol = http
.baseURL(“https://placeholder.com”)
.proxy(Proxy(“proxy.placeholder.com”, 88).httpsPort(88))
.inferHtmlResources()
.userAgentHeader(“Java/1.8.0_73”)

val headers_GetAccessToken_App_0 = Map(
“Accept” → “application/json”,
“Accept-Encoding” → “gzip,deflate”,
“Content-Type” → “application/json”
)

val headers_GetAccessToken_App_1 = Map(
“Accept” → “application/json”,
“Accept-Encoding” → “gzip,deflate”,
“Content-Type” → “application/json”
)

val headers_GetAccessToken_App_2 = Map(
“Accept-Charset” → “UTF-8”,
“Accept” → “application/json”,
“Accept-Encoding” → “gzip,deflate”,
“Content-Type” → “application/json”
)

val GetAccessToken_App_0 = scenario(“GetAccessToken_App_0”)
.exec(http(“request_GetAccessToken_App_0”)
.post(“https://placeholder.com/password=placeholder”)
.headers(headers_GetAccessToken_App_0)
.check(jsonPath("$.id_token").find.saveAs(idToken)))
.pause(1)
.exec(http(“request_GetAccessToken_App_1”)
.post(“https://placeholder.com/mobile/register”)
.headers(headers_GetAccessToken_App_1)
.body(RawFileBody(“Payload_GetAccessToken_App_1.txt”))
.check(jsonPath("$.client_id").find.saveAs(clientID)))
.pause(5)
.exec(http(“request_GetAccessToken_App_2”)
.post(“https://placeholder.com/token="+"${idToken}”)
.headers(headers_GetAccessToken_App_2)
.header(“x-client-id”, “${clientID}”)
)

setUp(GetAccessToken_App_0.inject(atOnceUsers(1))).protocols(httpProtocol)
}
`

I get: “Failed to build request request_GetAccessToken_App_2: No Attribute named ‘idToken’ is defined” as an error when I run the simulation and can’t seem to find out how to fix it.

Thanks in advance,
Wolfgang

PS: ignore the URLs, they have been changed to omit sensitive information

Hi Wolfgang,
You need to use quotes around the attribute name (saveAs param):

.check(jsonPath("$.id_token").find.saveAs("idToken")))

And no need to have a variable for that.

Hi Julia,

thanks for the quick answer. It seems to work, though I can’t really say since the servers I’m testing on are down atm. :frowning:

thanks a lot,
Wolfgang

PS: for being such an easy fix I wasted way too much time on this :slight_smile: