POST JSON: exception value fileBody is not a member of io.gatling.http.request.builder.PostHttpRequestBuilder

Hi group,

I am beginner trying to learn load testing with gatling.

I am trying to POST a JSON in a simulation like so:

exec(http(“addLocation”)

.post("/users/${id}/location")

.headers(headers_7)

.queryParam(""“operation”"", “”“addLocation”"")

.fileBody(“myTemplate”, Map(“loc” → “${loc}”)).asJSON)

Here is my myTemplare.ssp:

{“country”:“US”,“loc”:"<%= loc %>",“zip”:94087}

Basically my use case is to post a JSON in which the loc is coming from a csv that I am feeding to the scenario. So I have the CSV that gives the loc which I am feeding into myTemplate.ssp. I need to POST 3 values like in the template but country and zip are hardcoded. Only loc is the variable.

I am getting value fileBody is not a member of io.gatling.http.request.builder.PostHttpRequestBuilder exception when I run gatling.sh

I was wondering if I was missing something. Also, is this the correct approach?

Thanks!

All right. I got past that error. It looks like I need to use sspTemplateBody (although it seems to be deprecated). It is the only one that works with out any compiler errors.

Anyway, I ran the tests and I get this error now:

17:56:40.798 [ERROR] i.g.h.a.HttpRequestAction - Ssp body file /Users/motiver/dev/gatling-charts-highcharts-2.0.0-M1/user-files/request-bodies/myTemplate doesn’t exist

I can see the file is present in the directory. it is saved as myTemplate.ssp.

Any pointers on this one?

Thanks,

Another update. sspTemplateBody requires file extension also.

exec(http(“addLocation”)

.post("/users/${id}/location")

.headers(headers_7)

.queryParam(""“operation”"", “”“addLocation”"")

.sspTemplateBody(“myTemplate.ssp”, Map(“loc” → “${loc}”)).asJSON)

Now it looks like it is complaining about the template itself

Here is my template file:

{“country”:“US”,“loc”:"<%= loc %>",“zip”:94087}

here is the run time error I get:

error: not found: value loc

{“country”:“US”,“loc”:"<%= loc %>",“zip”:94087}

Hi,

ssp is quite a pain in the butt (you have to properly read both Gatling AND Scalate documentation) and was not really efficient.
https://github.com/excilys/gatling/wiki/HTTP#wiki-template-body

Generally speaking, the Wiki is about Gatling 1. Gatling 2 hasn’t been released yet, and Github can’t have multiple wiki versions online (that’s why we’ll move the docu out out the wiki in the next months).
If you wan’t to know about Gatling 2, please have a look here:
https://github.com/excilys/gatling/wiki/Gatling-2

Note that ssp has been deprecated in 2.0.0-M2 but has been dropped in master (so upcoming 2.0.0-M3). With Gatling 2, writing bodies is so much more simple.
For exemple, you can use elTemplateBody and just use a simple text file with Gatling EL: https://github.com/excilys/gatling/wiki/Gatling-2#wiki-bodies

If you use this, assuming you have a loc attribute in your session, your template would just be:
{“country”:“US”,“loc”:"${loc}",“zip”:94087}

Cheers,

Stéphane

Thanks for hint. In my case ${loc} comes from a csv file. It is not in the session. But I will try with this method.

By “it comes from a csv file”, you probably mean that “it was injected thanks to a feeder”. If so, it’s indeed an attribute in the session.

Hi Stéphane,

I’m trying to use a session attribute that is a List[String] to use inside a json document but I’m getting this:

ArrayBuffer(924.2997802, 924.2928845, 924.2932492, 924.2939818, 924.2940272, 924.2925543, 924.2935960, 924.2934811, 924.2931511, 924.2934318, 924.2935909, 924.2939719, 924.2922192, 924.2922266, 924.2922419, 924.2922638, 924.2957470, 924.2937862, 924.2932691, 924.2957211, 924.2957282, 924.2933830, 924.2933158, 924.2935021, 924.2938410, 924.2931361, 924.2934673, 924.2938128, 924.2929508, 924.2933154)

I’m using EL inside a template to replace the variable.

Thanks,
Pedro

I just found a way to solve the problem:

.exec(session => {
val marketIds = session(“marketIds”).asOption[List[String]].get.mkString("["","","", “”]")
println("MarketIds: " + marketIds)
session.set(“marketIdsString”, marketIds)
})

Cheers,
Pedro

"I’m trying to use a session attribute that is a List[String] to use inside a json document but I’m getting this:

ArrayBuffer(924.2997802, 924.2928845, 924.2932492, 924.2939818, 924.2940272, 924.2925543, 924.2935960, 924.2934811, 924.2931511, 924.2934318, 924.2935909, 924.2939719, 924.2922192, 924.2922266, 924.2922419, 924.2922638, 924.2957470, 924.2937862, 924.2932691, 924.2957211, 924.2957282, 924.2933830, 924.2933158, 924.2935021, 924.2938410, 924.2931361, 924.2934673, 924.2938128, 924.2929508, 924.2933154)"

This simply means that what you think is a List[String] is actually an ArrayBuffer[String].

Thanks Stéphane!

You’re welcome.
Have fun!