No attribute named X is defined using elTemplateBody, Gatling 2.0.0 M2

Hi,
This is what I am doing:

val scn = scenario(“Something”)
.feed(csv(“users.csv”))

.exec(http(“Uploading a file”)
.post(“someURL”)
.headers(someHeaders)
.header(“key”,"${key}")
.rawFileBody(“fileToUpload.txt”)
)
.pause(1)
.exec(http(“Action number 2”)

.post(“secondURL”)
.headers(moreHeaders)
.header(“key”,"${key}")
.elTemplateBody(“myJSONbody.txt”)
)
.pause(1)

setUp(scn.inject(atOnce(1 user)).protocolConfig(httpConf))

In my users.csv file I have:
username, connection_id, key, user_id
someUsername, 23, 234sd, 2

In the body Im sending myJSONbody.txt file which has:

{
“connection_id”: “${connection_id}”

}

When running the test I get:
[ERROR] i.g.h.a.HttpRequestAction - No attribute named ‘connection_id’ is defined

For what I understood the elTemplateBody option was useful for this, am I using it wrong? How should it be? Or what other options do I have?.

Thank you!.
Amina.

Hi,

I don’t see anything wrong in the sample you provided.
I can’t find any bug related to this in the M3 milestone content, but then, it was released 6 months ago, so I can’t tell for sure.

What happens if you try this instead?

.body("""{

“connection_id”: “${connection_id}”

}""")

Cheers,

Stéphane

Fixed this problem adding:

.exec(session => {
val newSession = session.set(“connection_id”, “${connection_id}”)
newSession
})

But now it doesn’t replace the ${connection_id} value with the actual number value in my JSON file.

No, there’s no way this would work: EL are not compiled inside functions. Here, you just set the “connection_id” attribute with the String “${connection_id}” (raw, not parsed and turned into a function).

If what you did changed something and you got a different result, I’m almost sure that either your feeder is not being called (misplaced or not properly chained), or that there’s a typo somewhere (like the csv column name not matching the expected attribute name expected inside your EL file).
Could you check this, please?

Hi,

The idea of:

.body("""{
“connection_id”: “${connection_id}”
}""")

Would not work for me because my JSON has a lot of other attributes besides ‘connection_id’, that’s why we have it in a separate txt file, the only one that is dynamic is ‘connection_id’.
I double checked for typos but didn’t find any.

I placed the feeder where I described on the first post, should I place it somewhere else too?.

Is there another way to feed a body file?.

Thank you!

I must insist, there are indeed typos! :slight_smile:

There are spaces after the commas in your CSV file, and those are considered meaningful (see RFC http://tools.ietf.org/html/rfc4180 ch 2.4), so the attribute that get injected in your Sessions is "connection_id ", not “connection_id”.

Please remove all of them.

Cheers,

Stéphane

Stéphane,
Indeed, I removed the spaces and it worked!!.
Im sorry for the time spending! hehe.

Thank you very much!

Amina.

You’re welcome.

Have fun!