Bean shell 脚本,用于检查 jmeter 中的响应文本中是否存在响应 A 或 B

Bean shell scripting to check if response A or B is present in response text in jmeter

如何使用 beanshell 脚本断言验证 jmeter 中的响应文本中是否存在响应 A 或 B

Beanshell Assertion 提供以下预定义变量:

  • ResponseData - 字节数组,包含父采样器响应
  • Failure - 布尔值,表示断言(和范围内的采样器)is/are 是否成功
  • FailureMessage - 可用于提供自定义错误消息的字符串

检查响应是否包含 A 的示例代码,如果不包含 - 采样器失败。

String response = new String(ResponseData);

Failure = !response.contains("A");
FailureMessage = "Response didn't contain A"; 

更多信息:How to Use JMeter Assertions in Three Easy Steps