Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set http status code 200, 400, 422, 202 set as success in JMeter

Tags:

jmeter

In my test plan I want to mark all the response with, http status code 200, 400, 422, 202 set as success.

Is there any way I can achieve this in a single assertion ?


2 Answers

Another solution could be with a Response Assertion

Add the Response Assertion into the Test Plan. This will ensure the Assertion is applied to all the Samplers (Responses)

enter image description here

Then configure the Response Assertion

  1. Field to Test as Response Code
  2. Pattern matching rules to Equals and Or
  3. Click the Add button and add the response codes

enter image description here

In addition to the above configuration, you may check the Ignore Status if you want to Instructs JMeter to set the status to success initially.

enter image description here

enter image description here

like image 137
Janesh Kodikara Avatar answered Dec 11 '25 07:12

Janesh Kodikara


You should also include what you have tried so far, to resolve this it is very simple,

Need to include a JSR223 assertion with the following script,

if("400".equals(SampleResult.getResponseCode()) || "200".equals(SampleResult.getResponseCode()) || "202".equals(SampleResult.getResponseCode()) || "422".equals(SampleResult.getResponseCode())) { 
    SampleResult.setSuccessful(true); 
    AssertionResult.setFailure(false); 
} 
else {
    AssertionResult.setFailure(true); 
}
like image 36
Jyoti Prakash Mallick Avatar answered Dec 11 '25 07:12

Jyoti Prakash Mallick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!