我正在尝试使用 jmeter json 提取器在 api 中获取响应变量的动态值,并使用子字符串的响应断言来断言它

I am trying to get dynamic value of a response variable in an api using jmeter json extractor and using reponse assertion of substring to assert it

但是,我无法在断言中获得所需的响应。我使用了 json 提取器并给出了 创建的变量名称为:contenttype

Json 路径表达式:$..contenttype

默认值:内容类型

并且在我给出的以模式作为子字符串的响应断言中 “内容类型”:${内容类型}

但在结果中,我收到了断言失败消息,例如 test expected to contain /"contenttype:":VOD/

我们不能不看到:

  1. 响应(至少部分)
  2. 您的 contenttype 变量值(可以使用 Debug Sampler 可视化)
  3. 响应断言的放置(我说的是Scoping Rules

到目前为止我只能说:

  1. JMeter Variables 的正确语法是 ${your-variable-name-here} 因此您可能希望将表达式更改为 "contenttype":${contenttype}

  2. 如果contenttype变量的值应该是String——在JSON中需要用引号括起来

    "contenttype":"${contenttype}"

  3. 如果 : 周围有空格,例如 "contenttype" : "VOD",您的响应断言将失败