Working with GatlingHttpFunSpec

31 views
Skip to first unread message

Michael Reardon

unread,
Mar 14, 2018, 9:31:08 PM3/14/18
to Gatling User Group
GatlingHttpFunSpec looks really interesting.  I've been trying it out and could use some advice. I'm able to have one spec save information to use in a second, but programmatically setting session variables for an EL template is eluding me. Below is a flawed example of what I'm attempting to do.


spec {
http("Request Access token")
.post("/oauth/token")
.basicAuth(apiKey, apiSecret)
.queryParam("grant_type", "password")
.queryParam("username", "ad...@example.com")
.queryParam("password", "password")
.check(success, jsonPath("$.access_token").ofType[String].saveAs("accessToken"))
}

spec {
  // this doesn't work, but what would?
exec(session => session.set("name", "Foo"))

http("Create a foo")
.post("/v1/foos")
.header("Authorization", "Bearer ${accessToken}")
.body(ElFileBody("postRequest_v1.json")).asJSON
.check(status.is(201))
}


Often with this sort of test, I need to first make other requests to set up the test data.  Is it possible to use "HttpDsl" outside of a "spec" function for that?  For example, could the access token request above be made without it being in spec function (ideally in a "doIf" function)?

Thanks for any guidance,

Mike


Reply all
Reply to author
Forward
Message has been deleted
0 new messages