0

I extract a JsonArray containing a list of string, and I want to validate by a regex each string inside this object. Problem, I don't seem to find any answers on the Taurus' website. Do you know how I can do it ? Example below:

# Verification of value inside the JsonArray
    extract-jsonpath:
      names: $.names
  - foreach: name in names
    do:
    - jsonpath: ${name} # if this JSONPATH is not found, assert will fail
      validate: true # validate against an expected value
      expected-value: "\\w" # value we're expecting to validate. [default: false]
      regexp: true  # if the value is regular expression, default: true
      expect-null: false  # expected value is null
      invert: false # invert condition
MrNierda
  • 412
  • 1
  • 8
  • 19

1 Answers1

2

I don't think it is possible with Taurus YAML syntax as:

  1. foreach keyword generates a normal JMeter ForEach Controller
  2. These jsonpath, validate, etc. are applied to a Sampler by default, they will not work if you add them just as children of the ForEach Controller

Assuming above points I would suggest adding a JSR223 PostProcesssor to perform all the checks. In Taurus it is being done via JSR223 Blocks like:

- url: https://api.example.com/v1/media/search
  extract-jsonpath:
    names: $.names
  jsr223:'1.upto(vars.get("names_matchNr") as int,{if (vars.get("names_$it").matches("\\w+")) {prev.setSuccessful(false)}})'  

See The Groovy Templates Cheat Sheet for JMeter article to get more ideas with regards to what can be done using Groovy scripts.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133