Search code examples
jmeterresponseassertion

Jmeter - Common Response assertion for multiple request


I want a common Response assertion for 200 response code which should be applicable for each sampler request.

However it is also required for some sampler requests to overwrite that from sampler level as (response code 204,500).

Is there any possible way to achieve this?


Solution

    1. JMeter Assertions obey Scoping Rules so if you put an Assertion on the same level as Samplers - it will be applied to all samplers
    2. If you need to override expected response code for a specific sampler I would recommend changing the response code to 200 via JSR223 PostProcessor like:

      if (prev.getResponseCode().equals('500')) {
          prev.setResponseCodeOK()
      }
      

      this way the above Groovy code will change the individual sampler status code from 500 to 200 so "global" assertion will still be successful.