JSON Feeder trouble (2.1.5)

Hi there,

Currently browsing through a couple of stress tools and gatling looks promising so far.

It does seem to fit one of my requirements, which is to spawn several different users for a said test.

I found out that Feeders might just do the job, but I have some problems implementing it. This is what I tried so far.

I attempt to have the following structure for my tests :

`
class UserSignIn extends Simulation {
val httpProtocol = http
// […]

val feedUser = jsonFile(“users.json”)
val scn = scenario(“User signing in”)
.feed(feedUser.random)
.exec(SignIn.signin, /* A few more scenarios executing */, SignOut.signout)

setUp(
scn.inject(
atOnceUsers(20)
)).protocols(httpProtocol)

object SignIn {
// A few headers

val uri1 = “https://some.domain

val signin= exec(
http(“sign_in”)
.post("/api/users/sign_in")
.headers(headers_0)
.body(//)
.resource(
// A few more calls
)
).pause(15)
}

object SignOut {

// More cool stuff !

}
}

`

My JSON file looks like this :

`
[
{
“user”: {
“login”: “”,
“password”: “”,

// A few more parameters

}
}, {
// A couple more users
}
]
`

I have no idea how to use the fed user in the body part.
Of course, it returned a 401 (but compiled !).
I tried to add a couple .queryParam() , as specified, which prevented my code to compile.

After messing around and reading stuff here and there, I decided to ask this Google Group.
I also read this
article, which was outdated (Gatling: 1.5.3), but decided to give it a try.

So I changed my feeder to use a tsv and used this body line :

.body("${user}") .asJSON

And re-arranged my JSON like this :

`
user
{{“user”:{“login”:"",“password”:""//}}
{{“user”:/* …/}}
{{“user”:confused:
…*/}}

`

This time, I got a different error message :

`

GATLING_HOME is set to //gatling
11:05:37.786 [ERROR] i.g.c.ZincCompiler$ - //gatling/user-files/simulations/user_signin/user_signin.scala:35: type mismatch;
found : String("${user}")
required: io.gatling.http.request.Body

`

I am kind of lost now… Anyone might giving me some advices ?

I hope I provided enough details about my situation.

Thanks,
Alexis

Exactly what happens when reading some outdated random article instead of the official documentation :slight_smile:

In Gatling 2, body takes a Body object, not a String:
http://gatling.io/docs/2.1.5/http/http_request.html#request-body

Oh, but I have read your documentation and I tried to use body(StringBody("${user}").asJSON which won’t work either.

It seems like a character escaping problem, because when I consult my log files, I can see the following :

`
{user": {“login”: “”,“password”: “”,“remember_me”: false,“language”: “fr”}}

`

The leading " as disappeared from my line, even if it is correctly written inside the file :

`

user
{“user”: {“login”: “”,“password”: “”,“remember_me”: false,“language”: “fr”}

`

But if I print the exact same line, with character escaping, inside the StringBody() function, it does work.

Character escaping parsing ? :slight_smile:

Ok, I did put some character escaping in front of every " encountered and wrapped my JSON inside a string, which worked.

So, tsp seems to work. I might prefer sticking to my JSON files, as they are used in some other tests.

Any advices on how to use the JSON Feeder with my desired structure ?

Ok, I did put some character escaping in front of every *"* encountered
and wrapped my JSON inside a string, which worked.

So, tsp seems to work. I might prefer sticking to my JSON files, as they
are used in some other tests.

Double quote is a special character in CSV and the likes.
It's used to protect String values that might contain the same char used as
separator.
See rawSplit doc
<http://gatling.io/docs/2.1.5/session/feeder.html#csv-feeders>.

Any advices on how to use the JSON Feeder with my desired structure ?

JsonFeeder is used for injecting DATA, ie, it's parsed into an object AST.
If you want to convert back to JSON, you can use for example jsonStringify.
See jsonStringify doc
<http://gatling.io/docs/2.1.5/session/expression_el.html#expression-language>
.

Alexis,

Try triple quote to see if that works in your case:
http://gatling.io/docs/2.1.5/advanced_tutorial.html?highlight=triple%20quote

.body(StringBody("""${user}""")).asJSON