简体   繁体   English

我无法在 JMeter 中使用 BeanShell PostProcessor 忽略失败的响应代码/消息

[英]I am unable to ignore the failed response code/message using BeanShell PostProcessor in JMeter

I am having multiple sampler in which i am trying to setup a script which ignores an error message or any response code and tryinh to make a sampler as "pass".我有多个采样器,我试图在其中设置一个忽略错误消息或任何响应代码的脚本,并尝试将采样器设置为“通过”。

but i am unable to do that.但我做不到。

Below is my configuration.下面是我的配置。

JMeter Configuration for BeanShell Post Processor JMeter BeanShell 后处理器的配置

You can see that in an benshell postprocessor i tries to ignore 3 responses (non http, 504 and 401)您可以看到,在 benshell 后处理器中,我试图忽略 3 个响应(非 http、504 和 401)

But in the "View Result Tree" listner i am still getting ignored status code as failed.但是在“查看结果树”监听器中,我仍然被忽略为失败的状态代码。

Response回复

You can see in an image that 401 error code request is failed.您可以在图像中看到 401 错误代码请求失败。

Can you please let me know what i am doing wrong here.你能告诉我我在这里做错了什么吗?

I also tried jsr223 response assertion,but not able to get expected output.我还尝试了 jsr223 响应断言,但无法获得预期的 output。

I also checked my logs as well.我也检查了我的日志。

There are multiple problems with your script:您的脚本存在多个问题:

  1. You're using == instead of equals() which compares references and not instances so it might be the case the code is not executed at all您正在使用==而不是比较引用而不是实例的equals()所以可能是代码根本没有执行的情况
  2. Setting response code to 200 is not sufficient to suppress the failure, you need to additionally invoke prev.setSuccessful(true) function将响应代码设置为200不足以抑制失败,您需要额外调用prev.setSuccessful(true) function
  3. Since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting because Groovy performance is much better comparing to Beanshell 由于 JMeter 3.1 建议使用 JSR223 测试元素和 Groovy 语言编写脚本,因为 与 Beanshell 相比,Groovy 的性能要好得多
  4. You might want to use switch statement instead of multiple if/else clauses您可能希望使用switch语句而不是多个 if/else 子句

Hello why you use JMeter do you know K6: https://k6.io/ It's better than JMeter你好为什么用JMeter你知道K6吗: https://k6.io/比JMeter好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们可以使用 Jmeter 从 BeanShell PostProcessor 中的响应断言打印成功消息/断言结果吗? - Can we print success message/Assertion Result from Response Assertion in BeanShell PostProcessor using Jmeter? 在jmeter中使用Beanshell验证JSON响应 - Validating JSON Response using Beanshell in jmeter 当我在jmeter中将脚本与Beanshell Sampler一起使用时出现错误,因为无法初始化类 - I am getting error when I am using Beanshell Sampler with script in jmeter as Could not initialize class Jmeter BeanShell-访问响应数据-Beanshell错误? - Jmeter BeanShell - Access Response Data - Beanshell error? 如何在 Beanshell PostProcessor 中打印 JDBC 请求和响应标头 - how to print the JDBC request and response headers in Beanshell PostProcessor 如何在Beanshell PostProcessor中获取一个或多个Http采样器响应 - How to get one or more Http sampler Response in Beanshell PostProcessor Jmeter中的Beanshell断言成功消息 - Beanshell assertion successfull message in Jmeter 无法使用beanshell在jmeter中使用动态路径重命名文件 - unable to rename file with dynamic paths in jmeter using beanshell 我应该如何将Java代码隐藏到Jmeter BeanShell Sampler中 - How should I covert my Java code into Jmeter BeanShell Sampler beanshell采样器,我想从jmeter访问Java代码 - beanshell sampler, i want access java code from jmeter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM