random values in request body for 'repeat'


I am using gatling 1.5.2. I have a scenario where I need to give random values in post request body. The post is in ‘repeat’ status for say 20. For each of these 20 post request, I need to give a random in id attribute of post request xml.

<?xml version="1.0" encoding="UTF-8"?>2013-02-26T07:59:15Z

I used tid=“UC00-”""+Random.nextInt+"""" but while in the loop, the value is same for all post requests. Could you help?

How do you set the body?

I set the body as below:

val scnPE = scenario(“PEServer”)


.repeat(20) {exec(http(“Trigger”)


.body(****""“<?xml version="1.0" encoding="UTF-8"?>tid=“UC00-””"+Random.nextInt+"""“2013-02-26T07:59:15Z”"")



.pause(0 milliseconds, 30000 milliseconds)


You’re passing a static String that’s evaluated once when the scenario is built, while you should be passing a function that’s evaluated every time a request is to be sent.

**.body(**session => “”“<?xml version="1.0" encoding="UTF-8"?>tid=“UC00-””"+Random.nextInt+"""“2013-02-26T07:59:15Z”"")

Thanks Stephane, it worked.

Hi Stephane,

One more issue - I am using csv feeder as input. My request body has to get the value from csv and send the request. But my request does not contain the value from csv. am giving the request body as below :

val scn = scenario(“test”)




.body(session =>"""<?xml version="1.0" encoding="UTF-8"?>




That’s because you pass a function. The implicit EL compilation only happens if you pass a String.

=> .body("""<?xml version="1.0" encoding="UTF-8"?>


thanks a lot for quick reply, I could get it done.

Hi Stephane,
I have a scenario where I need EL compilation and function call.

.body(session =>""“<?xml version="1.0" encoding="UTF-8"?>open<ucid version=“1.0” tid=“UC00-””"+Random.nextInt+"""" …/>

here I need to have the value of ${tn} to be read from csv and Random.nextInt to be different for each of the entries in csv.

how can I achieve this ? could you help?

Which version do you use?

1.5.2, because of having to execute more than one scenarios at the same time, I am forced to use this. You had given the reply earlier that multiple scenario implementation is currently not in the latest release but will be coming up in master releases.

You can’t combine both. If you go with functions, you have to use the Session API.

.body(session =>"""<?xml version="1.0" encoding="UTF-8"?><presence entity=“ppp:+”"" + session.getAttribute(“tn”) +"@jpp.ccsdf.net" >open<ucid version=“1.0” tid=“UC00-”""+Random.nextInt+"""" …/>

It is working Stephane, thanks once again.

.body(StringBody(session => """{"persons": [
                       {"uId": {"emailAdrs": """"+emailAdrs()+""""},
                       "accountTId":"${AccountTId}" ,
                       "givenNames": """"+Name()+"""",

I want to print el and variable in a string body… if i use session.get(“AccountTID”) it is returing the whole session variable how to get value for the session variableI am using 2.2.0 version in gatling

Hi Stephane,

I have posted in the following way where i am posting json with random value for the input field, but it works in the thread level.
Random is same for repeat . Can you please suggest me the approach for getting random for each repeat?

exec(session => session.set(“Test1”, “valuexml”+ random.nextInt(40000)))


I am able to resolve this issue by calling session.set inside repeat block.

.repeat(2){exec(session => {session.set(“Test1”, “valuexml”+ random.nextInt(40000))}).exec(request1)}