Attribute Assignment Issue - No attribute named 'x' is defined

Hi folks. I’m new to Gatling and to Scala - love the tool so far!. I’ve got an issue with my scenario when I try to use a pre-defined string val inside of my request body. In the code below, I define “list” and attempt to use it the step “add_collaborators” which results in “[ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘list’ is defined”

What simple thing am I missing?

object upload {

val list: String = “”"{“email":"user1@test.company.com”},{“email":"user2@test.company.com”},{“email":"user3@test.company.com”}"""
val name: Expression[String] = (session: Session) => s"""{“name”:"${ThreadLocalRandom.current.nextInt(100000).toString}", “parentId”:“0” }"""
val scn = scenario(“End to End”)

.exec(
http(“get_token”)
.post(“http://url.company.com/api/oauth/token?grant_type=password&client_id=client1&client_secret=secret1&username=user76@test.company.com&password=password”)
.body(StringBody("{}"))
.check(status.is(200))
.check(jsonPath(".access_token").find.saveAs(“token”)))

.exec(
http(“get_key”)
.post(“http://url.company.com/api/v1/keys”)
.headers(headers_1)
.header(“Authorization”, “Bearer ${token}”)
.body(StringBody("""{}"""))
.check(status.is(200))
.check(jsonPath(“keys[0].id”).find.saveAs(“keyId”)))

.exec(
http(“create_folder”)
.post(“http://url.company.com/api/v1/collections”)
.headers(headers_1)
.header(“Authorization”, “Bearer ${token}”)
.body(StringBody(name))
.check(status.is(200))
.check(jsonPath(“id”).find.saveAs(“collectionId”)))

.exec(
http(“add_collaborators”)
.put(“http://url.company.com/api/v1/collections/${collectionId}”)
.headers(headers_1)
.header(“Authorization”, “Bearer ${token}”)
.body(StringBody("""{“id”:"${collectionId}",“collaborators”:{“recurse”:true,“add”:[${list}],“remove”:[]},“accessControls”:{“add”:[],“remove”:[]}}"""))
.check(status.is(200))
.check(jsonPath(".id").find.saveAs(“objectId”)))

etc…

Hi,

The String “”"{“id”:"${collectionId}",“collaborators”:{“recurse”:true,“add”:[${list}],“remove”:[]},“accessControls”:{“add”:[],“remove”:[]}}""" isn’t prefixed with s like in val name, so it uses Gatling EL, not Scala String interpolation.

Gatling EL is used to resolved user specific session attributes, meaning that the attribute had to be previously injected, be it with a feeder, a check with saveAs, or manually. Here, list hasn’t been injected.

Here, as list is (maybe just for now) just a static value, so you could use String interpolation.
If what you want is play with Gatling EL, you have to inject list as an attribute named “list” into users’ session, for example, with an exec(function):

.exec(session => session.set(“list”, list))

Cheers,

Stéphane

Awesome. Perfectly explained, thanks a lot!

You’re welcome.
Have fun!