Kishor Chintala
Kishor Chintala

Reputation: 13

regex check and proceed next call

Iam new to gatling and scala. I was trying to validate regex in galting-scala. My scenario. from the response capture (regex) X values, If available then execute step-ABC If X value of component not found, ignore step_ABC

Upvotes: 1

Views: 425

Answers (1)

James Warr
James Warr

Reputation: 2604

Your example uses .exists, which asserts that the regex must be matched and returns a boolean, not the value of the match. So the "logoId" session variable will always get set, but won't have any data useful for making a subsequent request. Additionally, since the logo is optional in your case, you don't want the scenario failing if it isn't there.

Optional checks and the gatling EL support your use-case.

.exec(
   http("get merchant") 
   .get("some url")
   .check(
     regex(""""logoId":(.+?),""").optional.saveAs("logoId")
   )
   .doIf("${logoId.exists()}") {
     exec(...)
   }

Upvotes: 3

Related Questions