Gatling 3.1 - Dynamic value capture & repeat loop

Hi

I have captured all Ids using jsonPath, findall in a parameter called Para_Ids

Now I would like to use a condition. if < 3 then run 1 iteration only else 5 iteration so I implimented this as follows

val rnd: Random = new Random()
val RndVal = rnd.nextInt(5)

.doIfOrElse( RndVal < 3 )
{
exec(http(“Page ${Para_Ids(0)}”)
.get("/computers?p=${Para_Ids(0)}"))
.pause(1)
}{
repeat(5, “n”) { // 1
exec(http(“Page ${Para_Ids(${n})}”)
.get("/computers?p=${Para_Ids(${n})}")) // 2
.pause(1)
}
}

but this is throwing Failed to parse ERROR

any idea what’s wrong here?

Can anyone help me, please?

I can get something like you doIfOrElse block to work…

val rnd: Random = new Random()
val RndVal = rnd.nextInt(5)

def temp: ScenarioBuilder =
  scenario("test scenario")
  .doIfOrElse(RndVal < 3) {
    exec(http("testOne").post("[http://httpbin.org/anything](http://httpbin.org/anything)").body(StringBody("one")))
  }
  {
    repeat(5, "n") {
      exec(http("testTwo").post("[http://httpbin.org/anything](http://httpbin.org/anything)").body(StringBody("${n}")))
    }
  }

so I don’t think that’s the source of your problem

keep in mind though, that switching like this won’t have the results you’re after. The DSL defines immutable builders, so ALL your users will end up having the same RndVal

to avoid this, you’ll need to supply a session function to your doIfOrElse

.doIfOrElse(session => rnd.nextInt(5) < 3) {