Increment session param in asLongAs loop


Could someone please explain how to can I use asLongAs with a counter?

Documentation states that

.asLongAs(condition, counterName) {
but it does not say how can I increment counter
I'm new to Gatling and Scala so have no clue how to implement this
Could you please provide some examples? 
Where is the counter stored and how can I address it? 
How to increment it? 
Can i use it in chain? 
For example, if I need to create 400 users:
.asLongAs(counter < 400, "counter"){
	exec((session => session.set("counter", sounter+1))
Will this work? 


Loops use a session attribute counter underneath. If you don’t specify a name, Gatling will generate a random uuid.
You can use it just as any normal attribute.

In your example, it seems that counter is an externally defined variable (counter < 400), so that won’t work.

Why don’t you use a simple repeat loop?

repeat(400, “counter”) {
exec(session => CreateUser(session(“counter”).as[Int]); session)


Need to read documentation more carefully.


Hi Shephane,

How about if you need to use a csv feeder?
I’ve also been reading the documentation but don’t actually know how to do it on my actual script.

Will this work?

val userCredentials = csv(“users.csv”).circular
val user_counter = userCredentials.records.size
val count = new java.util.concurrent.atomic.AtomicInteger(0)

.asLongAs(condition = _ => count.getAndIncrement() < user_counter, exitASAP = false) {

.get(uri1 + “/”)

session => session.set(“email”, “${email}”)

.post(uri1 + “/”)
.formParam(“location”, " ")
.formParam(“email”, “${email}”)
.formParam(“password”, “${password}”))


I want to add one condition in below scenario. Like I would like to exit from the scenario if counter=8 or WorkflowStatus=true
does anyone knows how to add increment counter variable and above condition in below scenario?

class LaunchResources extends Simulation {

val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
val userCount = Integer.getInteger("userCount", 1).toInt
val UUID = System.getProperty("UUID", "24d0e03")
val username = System.getProperty("username", "p1")
val password = System.getProperty("password", "P12")
val testServerUrl = System.getProperty("testServerUrl", "[](")

val httpProtocol = http
.basicAuth(username, password)

val headers_0 = Map(
"""Cache-Control""" -> """no-cache""",
"""Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")

val scn = scenario("LaunchAction")
.repeat (scenarioRepeatCount) {
.post( """/api/actions""")
.body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))



What happens if I want to set a time limit? How do I use asLong with a time condition, should I use a timer, how do I implement it?

This is purpose of during:
There is also asLongAsDuring and doWhileDuring to combine criterias and time constraints:

.during(5.minutes) {

Wait, in another thread you spoke about synchronize the limit limit for all users. Is this what you intend to do here?


what I really want to do is create a pattern like the image

image (137).png

I have several user groups that start when another group ends with similar configurations, what I want is to hold a group until a time and end suddenly, and then another group starts, this to not have at the same time the execution of two groups of virtual users

image (138).png

I’ve done this, but with the problem I’ve mentioned, in which two groups actually run for the same but short time, but ruins my pattern, this I’ve done with the command during(), but does not kill the groups but they wait to finish their flow, do not know if the image is seen in the overlap between two groups, what I really need is an example to end the flow of a group of users without waiting for them to finish, but that the simulation continues so that other groups do their thing.