金牛座/性能测试:验证JsonArray中的数据

时间:2018-08-07 06:53:57

标签: jmeter performance-testing taurus

我提取了一个包含字符串列表的JsonArray,并且我想通过正则表达式验证此对象内的每个字符串。 问题,我似乎在金牛座的网站上找不到任何答案。 你知道我该怎么做吗? 下面的示例:

# 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

1 个答案:

答案 0 :(得分:1)

我认为Taurus YAML syntax不可能实现:

  1. foreach关键字生成普通的JMeter ForEach Controller
  2. 这些jsonpathvalidate等默认情况下应用于Sampler,如果仅将它们作为ForEach Controller的子代添加,则它们将不起作用

假设以上几点,我建议添加一个JSR223 PostProcesssor来执行所有检查。在金牛座中,它是通过JSR223 Blocks完成的,例如:

- 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)}})'  

请参阅The Groovy Templates Cheat Sheet for JMeter文章,以获取有关使用Groovy脚本可以完成的操作的更多想法。