问题描述
我在参数化调用中将JMeter用作单元测试工具,我希望其中一些响应是500个内部服务器错误.我正在使用BeanShell断言来检查响应.
I am using JMeter as a unit test tool, in parameterised calls where I expect some of the responses to be 500 internal server errors. I am using BeanShell Assertions to check the responses.
如果响应包含指定的文本,我希望500个内部服务器错误中的一些不被标记为失败.所有500个服务器错误都标记为失败.可以更改行为吗?
I want some of the 500 internal server errors to NOT be marked as failures if the response contains a specified text. All 500 server errors are marked as failures. Is it possible to change the behavior?
下面是BeanShell断言的摘录.
Below is an extract from the BeanShell Assertion.
if (ResponseCode.equals("500")) {
Failure = false;
String respData = new String(ResponseData);
if (! respData.contains("specific Text")) {
Failure = true;
FailureMessage = "500 Internal Server Error: Unexpected Response. " +
"Response Message: " + respData;
}
}
谢谢您!
推荐答案
UPD:请找到最简单的&下面的本机"解决方案:
UPD: please find most simple & "native" solution below:
如果您想在代码中做一些棘手的事情,请使用以下方法.
In case if you want to do some tricky things in code use the following approach.
访问并修改 SampleResult 来更改状态如果您的 JSR223声明中的代码为500,则从失败"到通过"或使用 JSR223 PostProcessor -它们都可以访问SampleResult对象.
Access and modify SampleResult to change the status from "FAIL" to "PASS" if the code is 500 from your JSR223 Assertion or use JSR223 PostProcessor instead - they all have access to SampleResult Object.
1. JSR223断言
if (ResponseCode.equals("500") == true) {
SampleResult.setResponseOK();
/* the same is
SampleResult.setSuccessful(true);
SampleResult.setResponseCodeOK();
SampleResult.setResponseMessageOK();
*/
}
2. JSR223后处理器
使用prev
代替-访问附加了一个后处理器的采样器的SampleResult对象:
2. JSR223 PostProcessor
Use prev
instead - to access SampleResult object of the sampler to which one post-processor is attached:
if (prev.getResponseCode().equals("500") == true) {
prev.setResponseOK();
/* the same is
prev.setSuccessful(true);
prev.setResponseCodeOK();
prev.setResponseMessageOK();
*/
}
这篇关于JMeter如何不失败500个内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!