简体   繁体   中英

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

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?

正确阅读文档${tc.exists()}

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

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

Worked with:

.doIf(session => !session.contains("tc")) {
    ...
}

Check with Nil instead. It works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM