I think I’m just not up to speed enough with Scala to figure this out (using 2.0.0-SNAPSHOT from about a week ago) . I have a call which returns with some cookie values set, I need to grab one of these values and store it for POST’ing later:
You’re aware that Gatling will automatically send back to the server the suited cookies, right?
Why don’t you trust the builtin behavior? Did you get a bug, or do you have some specific needs?
Your NPE is probably because “10.18.8.30” is an IP address, no a URI. “http://10.18.8.30” is.
You can bypass CookieJar logic and directly access the underlying Map:
val cookiesForDomain = cookieJar.store.get(“10.18.8.30”).getOrElse(Nil)
cookiesForDomain.filter(_.getName == “xtok”).headOption match {
case Some(xtok) => session => session.set(“myCookieValue”, xtok)
case _ => session
}
If I read his question right he wants to POST the cookie value into some form.
As in, the server doesn’t read the posted cookie - it has a form field that expects a value that was put into a cookie value earlier.
Since I doubt gatling will replay the client javascript code that does that post normally this behaviour is pretty much expected.
Hi, I was hoping to get just xtok, but I seem to get an entire string using this code: (Prints: “xtok=45aa30c4-0a12-081e-00fe-b4056416f582; domain=10.18.8.30; path=/”)
.exec(session=>{
import io.gatling.http.cookie._
import java.net.URI
session(“gatling.http.cookies”).validate[CookieJar].map {
cookieJar =>
val cookiesForDomain = cookieJar.store.get(“10.18.8.30”).getOrElse(Nil)
cookiesForDomain.filter(_.getName == “xtok”).headOption match {
case Some(xtok) =>
session.set(“myCookieValue”, xtok)
case _ => session
}
}
}).exec(session=>{
println(session(“myCookieValue”).as[String])
session
})
If you want to just store the value, that’s session.set(“myCookieValue”, xtok.getRawValue)
or getValue if you want it decoded (if you escaped some characters)