doIf counter greater than zero

Hello,

I’m trying to write the following scenario, some users will browse a list of urls, some of them will add to cart and some of them will visit the cart page but ONLY IF the product count in cart is GREATER THAN 0.

`

val feeder = sitemap(“sitemap.xml”).random

feed(feeder)

.exec(
http(“Browse Pages”)
.get("${loc}")
.check(css(".count").saveAs(“cartCount”))

)

.exec(
http(“Add To Cart”)
.post("/checkout/cart/add")
.formParam(“product”, “1234”)

.check(css(".count").saveAs(“cartCount”))

)
.doIf(CONDITION) {

.exec(
http(“Browse Pages”)
.get("${loc}")
.check(css(".count").saveAs(“cartCount”))

)

}

`

I’ve tried the following, but none worked:

`
.doIf("${cartCounter} > 0")

.doIf("${cartCounter.greaterThan(0)")

.doIf(session(“cartCounter”) > 0)

`

Somehow, I also need to transform it to integer (I guess) before comparing.

Tried also to use .transform, but it either works if it’s greater than zero, or I get an error.

`
css(".count").transform(string => string.toInt).greaterThan(0).saveAs(“cartCountFlag”)

.doIf("${cartCountFlag.exists()}") {

}
`

Thank you in advance!

From http://gatling.io/#/cheat-sheet/2.2.2

Executes a chain when a condition is satisfied

(actual, expected){chain}
If the actual value is equal to expected, then, chain is executed.
(Session => Boolean){chain}
If the result of the function Session => Booleanis true, then chain is executed.

Try :
doIf(session => session("cartCount").as[Integer] > 0) {
...
}