jmeter 响应断言断言多个不同的模式

jmeter response assertion to assert more than one different patterns

例如,我的回复如下: {…… "messageStatus":"SUCCESS","warnings":[{"warningCode":1003,"warningMessage":"Warning when calling downstream service. service = repricing, reason = Warning(warningCode=2503, warningMessage=Sell rate 7.0000 must be within rate verification threshold."}]} 我想使用响应断言: 1.当messageStatus:success时,没有warningcode,响应成功 2.当response包含"warningcode"时,response为failure

那么如何使用响应断言来实现呢?我尝试使用两种响应断言:一种是 Contains: "messageStatus":"SUCCESS";另一个是 Substring 并检查 Not: "warningCode", 似乎可以实现我想要的,但我想使用更简化的方法来获得它,你能帮我或给些建议吗?谢谢。

您可以使用以下配置:

  • 模式匹配规则:Contains
  • 模式 1:"messageStatus":"SUCCESS"
  • 模式二:(?s)^((?!warningCode).)*$

如果出现以下情况,这种方式断言将失败:

  1. "messageStatus":"SUCCESS" 行未找到

  2. warningCode 找到行

Contains 模式 Response Assertion treats patterns as Perl-5 Style Regular Expressions 中,因此您可以完全灵活地定义自定义 pass/fail 条件。

更多信息:Response Assertions in JMeter 3.2 - New and Improved