dynamically editing request bodies in gatling2.0

How to update http request bodies in gatling 2.0 dynamically?

For eg,

body(ELFileBody(“RecordedSimulation_request_4.txt”)) I want to update some parameters inside the request.txt file, and need this to be done for all the request.txt files(around 100 files).

Is there anyway in script by which i can feed the data from csv file dynamically into these, instead of editing the all the files like below

request_4.txt:

[
{
“id” : 13183,
“time” : “${timevalue}”, // use regular Gatling EL

“login” : 2986,
“objects” : [
{
“id” : -23,
//…
“number” : 1

}
]
}
]

Sorry, but Gatling doesn’t rewrite request bodies dynamically, and there’s no good reason that it should…
You’ll have to edit them by hand, or with a script of your own.

Cheers,

Pierre

So if I want to run the script for multiple session for which the requests has some data that are specific for each session, is there any way to get that running?

After you edited your request bodies to use Gatling’s EL to inject data from the Session, yes, that would work fine.
But you’ll have to edit the request bodies beforehand.

Couldn’t be possible for you to reduce the number of requests bodies that you’ll need to handle ?
For example, I see a “login” key in your JSON request body. With the value of “login” being an integer, I guess that it currently logged-in user ID.
And then, if it’s the case, couldn’t you fetch the user ID from somewhere else ? Couldn’t you get this user ID by doing a check on the response to the login request of your simulation ?

Sorry Pierre, tat just an example. To be more clear about my prob,

I want to run a script that takes around 20 to 30 request bodies and each request body.txt file will have some values which is specific to a user. so basically when i want to run the script i want different information that needs to be feed into the request body from a csv file and run this simulation multiple times.

eg)

http(“request_74”)
.post(uri1 + “”"/""")
.headers(headers_25 ++ Map(“Cookie” → “SESSIONID=${sessionId}”))
.body(ELFileBody(“request_74.txt”))

and this request_74.txt wil have a data in which i need to update particular value for each different user i run.

so to edit “Id” in the request file, was trying something like below,

.body(ELFileBody(“request_94.txt”,Map(“Id” → “${token}”)))

but since you mentioned gatling doesnt dynamically update the request bodies, trying to figure out if there is anyother way to get it?

Wow, I think there’s was a huge misunderstanding here :slight_smile:
Of course your data from the Session can be injected into an ELFileBody to have bodies specific to each user, that’s the whole point of ElFileBody !
BTW, no need to provide anything else than the filename to ELFileBody, everything will be resolved from the Session automatically by ELFileBody.

What I said before is that Gatling won’t automatically “prepare” request bodies generated by the Recorder to be ELFileBodies. You’ll have to edit them so that they can make use of Gatling’s EL (e.g. replacing a “time”: “1234” by “time”: ${timevalue}).

Got it ?

So if I get it correctly I need to replace “time” in request file to ${timevalue} so that for each session corresponding value is obtained.(basically need to update all the request files similar to this)?

Indeed : modify your request bodies to make them dynamic by introducing Gatling’s EL where you need it.
But you don’t need to update ALL your request bodies…
If you happen to have several request bodies that are similar, you can keep only a handful of request bodies and parametrize them using Gatling’s EL.

If you end up with, let’ say 15, request bodies that looks like this :

`

[
{
“id” : 13183,
“time” : “1234”

“login” : 2986,
“objects” : [
{
“id” : -23,
//…
“number” : 1

}
]
}
]

`

And only the value of “time” differs, parametrize “time”, and keep only one request body.

Got it ?

Thanks Pierre. “But you don’t need to update ALL your request bodies…”? its not similar request, all are different ones.

Yeah, but I’m point I was trying to make is that if you have :

[
{
“id” : 1,
“time” : “1"
“login” : 1,
“objects” : [
{
“id” : -23,
//…
“number” : 1
}
]
}

`

]

`

[
{
“id” : 2,
“time” : “2"
“login” : 2,
“objects” : [
{
“id” : -23,
//…
“number” : 1
}
]
}

`

]

`

[
{
“id” : 3,
“time” : “3"
“login” : 3,
“objects” : [
{
“id” : -23,
//…
“number” : 1
}
]
}

`

]

Then you don’t need to keep three ELFileBodies.
You can keep only a single one :

[
{
“id” : ${id},
“time” : “${time}"
“login” : ${login},
“objects” : [
{
“id” : -23,
//…
“number” : 1
}
]
}

`

]

And use it as much as you want : just have different “id”, “time” and “login” attributes in Session for each user :slight_smile:

`

`

oh ok ok got it :slight_smile: yeah, in my case the requests are different all together,

[
{
“id” : x,
“time” : “1"
“login” : 1,
“objects” : [
{
“id” : -23,
//…
“number” : 1
}
]
}
]
[
{
“id” : x,
“logout” : “ccc”,

]
}
]
[
{
“id” : x,
“time” : “3"
data : “string”
]
}
]

basically different request but has same id, so i wanted to pass id to all these requests. So as per your explanation i need to make “id” : ${y} in all the requests to get the value.