Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
333 views
in Technique[技术] by (71.8m points)

assertion - JMeter how to NOT fail 500 Internal Server Errors

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.

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?

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;
    }
}  

Thank you and Regards

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Another possible solution is to use Response Assertion with checked "Ignore Status" flag added to your sampler:

Ignore status
Instructs JMeter to set the status to success initially.

The overall success of the sample is determined by combining the result of the assertion with the existing Response status. When the Ignore Status checkbox is selected, the Response status is forced to successful before evaluating the Assertion.

HTTP Responses with statuses in the 4xx and 5xx ranges are normally regarded as unsuccessful. The "Ignore status" checkbox can be used to set the status successful before performing further checks. Note that this will have the effect of clearing any previous assertion failures, so make sure that this is only set on the first assertion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...