doIf counter greater than zero

406 views
Skip to first unread message

Constantin Bejenaru

unread,
Oct 10, 2016, 10:47:09 AM10/10/16
to Gatling User Group
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!

Sajjad Lateef

unread,
Oct 10, 2016, 5:03:18 PM10/10/16
to gatling


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)  {
...
}

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sajjad Lateef  sajjadlateef (a) acm.org
slateef.gc (a) gmail.com
Reply all
Reply to author
Forward
Message has been deleted
0 new messages