can't get doIf with session check to work

Hi Guys,

I’m extracting an Id (optional) using a regex and with a check and saving that into a session. When I try to use doIf to verify if the session key exists in order to proceed, it keeps returning false even when I enabled debug and verify my session is there. What can be doing wrong? I’ve tried gatling 2.1.4 and 2.1.5 and using maven plugin.

Here is the extraction

Object MyObj { val sc = sncenario("MyScenario") http("getsomeids") .get("www.mysite.com") .check(regex("myregexhere").optional.saveAs("myId")) }

Here is the check

`
class mySimulation extends Simulation {

val myscn = scenario(“MyScenario”)
.exec(MyObj.sc)
.pause(3)
doIf(_.contains(“myId”)){
exec(http(“anotherRequest”)
.get(“www.mysite.com/anotherpage”)
}
}

`

This always returns false even though I enable logging (logback-test.xml) and I can see myId and it’s value (myId → 123). I’ve also tried many other different ways.

`
doIf(session => session.contains(“myId”)){
exec(…)
}

`

`
doIf(session => session(“myId”).as[String].length > 0 ){
exec(…)
}

`

Any ideas what I could be doing wrong?

Thanks!

Missing dot before doIf: the part of your scenario which set myId in the session does not get executed :slight_smile:
Simply add a dot before doIf and it should work.

Cheers,

Pierre

Wow. Can’t believe I overlooked that and kept scratching my head.

Thanks much for fast reply!