Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an attribute is present in Gatling/Scala

Tags:

scala

gatling

I would think this is probably easy to do, but I really don't know Scala at all.

I have a scenario where a first time user will log in and see a page, then if they log in again they won't see this page. So the best I've come up with so far is this:

val chain = exec(
http("Login page")
  .get("/en/login")
  .headers(Config.HTML_HEADER)
).exec(
      http("login request")
        .post("/en/j_spring_security_check")
        .formParam("j_username", """${username}""")
        .formParam("j_password", """${password}""")
        .check(status.is(200))
        .check(currentLocationRegex(".*termsAndConditions").optional.saveAs("tc"))
    )
    .doIf(session => !session("tc").equals(null)) { // this doesn't work 
      exec(AgreeTermsAndConditions.chain)
  }

So I've tried a bunch of things on the doIf, the goal is just do if session "tc" is not set. Is there an easy way to do that?

like image 727
rozner Avatar asked Mar 19 '15 10:03

rozner


1 Answers

Gatling provides an exists() built-in EL function (see Galting EL documentation), so a succincter solution would be:

.doIf("${tc.exists()}") {
 ...
}
like image 123
Camilo Silva Avatar answered Oct 04 '22 22:10

Camilo Silva