Problem to use "doIf"

Hi, I am trying to use the “doIf” feature, but it does not working.

I am using Gatling 2.0.0-RC3 version.

the error message is:

11:57:24.577 [ERROR] i.g.a.ZincCompiler$ - gatling/user-files/simulations/harpia/Startup.scala:23: value doIf is not a member of io.gatling.http.request.builder.HttpRequestWithParamsBuilder
possible cause: maybe a semicolon is missing before `value doIf’?
11:57:24.579 [ERROR] i.g.a.ZincCompiler$ - .doIf("${database_name}", “${database}”) {
11:57:24.580 [ERROR] i.g.a.ZincCompiler$ - ^
11:57:24.616 [ERROR] i.g.a.ZincCompiler$ - one error found

My imports is:

import io.gatling.core.Predef._
import io.gatling.core.session._
import io.gatling.core.structure.ConditionalStatements
import io.gatling.http.Predef._
import io.gatling.http.request.StringBody
import scala.concurrent.duration._
import harpia._

I was missing anything??
Since now, thanks.

Hi Everton,

It looks like you’re missing a right parenthensis somewhere in your scenario, as you’re seemingly trying to call doIf on a http(…) request instead of a exec(…) block.

Cheers,

Pierre

Sorry Pierre,
But I think I was using the doif in the exec(…) block. My code is following:

val scn = scenario(“Insertions”) // Cria o database
.feed(feederConfig)
.exec(http(“createDB”)
.post("/v1/databases")
.body(StringBody(""""{ “database_name”:${database} }""")).asJSON
.check(jsonPath("$[0].database_name").saveAs(“database_name”))
.doIfOrElse("${database_name}", “${database}”) {
println(“Database created.”)
} {
println(“Database already created.”)
}
)

I switch the doIf by a doIfOrElse.
But the error is the same.

Nope :

val scn = scenario(“Insertions”) // Cria o database
.feed(feederConfig)
.exec(http(“createDB”)
.post("/v1/databases")
.body(StringBody(""""{ “database_name”:${database} }""")).asJSON
.check(jsonPath("$[0].database_name").saveAs(“database_name”))) <— Missing parenthesis right here: first one close saveAs(…), second one close check(…), exec wasn’t closed.
.doIfOrElse("${database_name}", “${database}”) {
println(“Database created.”)
} {
println(“Database already created.”)
}
)

All right. But now that I put the new “)”. A new error appear:

12:38:24.267 [ERROR] i.g.a.ZincCompiler$ - gatling/user-files/simulations/harpia/Startup.scala:23: too many arguments for method doIfOrElse: (condition: io.gatling.core.session.Session => io.gatling.core.validation.Validation[Boolean])(thenNext: io.gatling.core.structure.ChainBuilder)(elseNext: io.gatling.core.structure.ChainBuilder)io.gatling.core.structure.ScenarioBuilder
12:38:24.269 [ERROR] i.g.a.ZincCompiler$ - ).doIfOrElse("${database_name}", “${database}”) {
12:38:24.269 [ERROR] i.g.a.ZincCompiler$ - ^
12:38:24.296 [ERROR] i.g.a.ZincCompiler$ - one error found
Compilation failed

the new code is:
val scn = scenario(“Insertions”) // Cria o database
.feed(feederConfig)
.exec(http(“createDB”)
.post("/v1/databases")
.body(StringBody(""""{ “database_name”:${database} }""")).asJSON
.check(jsonPath("$[0].database_name").saveAs(“database_name”))
).doIfOrElse("${database_name}", “${database}”) {
exec(http(“Database created”).get("/v1/imports"))
}
{
exec(http(“Database already created”).get("/v1/imports"))
}

Could you share your WHOLE simulation into a GIST, please?

Ofcouse. That’s it:

https://gist.github.com/anonymous/bb2b2a4a3ad87ea9c647

Is possible instead of use “check(…)” use other form to store information in some variable to use in the “doIf”??
Because if the “check” fail it returns an error. Like the check by status code = 201.

In your gist, there’s a missing “)” just before your .doIfOrElse in order to close the exec for the request.
Then, if your use doIfOrElse, you have to provide the alternative for the else. Otherwise, just use a doIf.