Reputation: 71
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")
Upvotes: 2
Views: 1415
Reputation: 12601
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)
Upvotes: 0
Reputation: 91
.check(jsonPath("$..name").in("abc" , "xyz")
Or
.check(jsonPath("$..fname").is("abc"), jsonPath("$..lname").is("xyz"))
Upvotes: 2