Gatling Check for logical operation like and & Or

1.3k views Asked by At

How to check value of a parameter either match with value "abc" or "xyz" in gatling. How to check for logical Or & And?

Something like

.check(jsonPath($..name).is("abc" || "xyz")

Or

.check(jsonPath($..fname).is("abc") || .check(jsonPath($..lname).is("xyz")
2

There are 2 answers

1
Nikolay Degkin On
.check(jsonPath("$..name").in("abc" , "xyz")

Or

.check(jsonPath("$..fname").is("abc"), jsonPath("$..lname").is("xyz"))
0
thoredge On

Gatling Checks leaves a little to be desired. I had a similar problem where I need to check that the Server-header is either Apache or undefined. I found a workaround with using transform like this:

.check(header(HttpHeaderNames.Server)
  .transformOption(n => if (n.contains("Apache")) None else n)
  .notExists)

Tried to engineer a similar solution for your problem. I think it works, but it seems very hacky:

.check(
  jsonPath("$..fname").optional.saveAs(fnameOrLname),
  jsonPath("$..lname").optional.saveAs(fnameOrLname))
.check(status
  .transform((_, s) => s(fnameOrLname).asOption[String]
  .filter(_.nonEmpty)
  .map(_ => 0))
  .exists)